AtCoder Beginner Contest 050 ABC题

A - Addition and Subtraction Easy


Time limit : 2sec / Memory limit : 256MB

Score : 100 points

Problem Statement

Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either + or -. Your task is to evaluate the formula instead of her.

Constraints

  • 1≦A,B≦109
  • op is either + or -.

Input

The input is given from Standard Input in the following format:

A op B

Output

Evaluate the formula and print the result.


Sample Input 1

Copy
1 + 2

Sample Output 1

Copy
3

Since 1+2=3, the output should be 3.


Sample Input 2

Copy
5 - 7

Sample Output 2

Copy
-2

 解法:没什么好说的

#include
using namespace std;
map<int,int>q;
long long h,m;
char s;
int main()
{
    scanf("%lld %c %lld",&h,&s,&m);
    if(s=='+')
    {
        printf("%lld\n",h+m);
    }
    else
    {
         printf("%lld\n",h-m);
    }
    return 0;
}

B - Contest with Drinks Easy


Time limit : 2sec / Memory limit : 256MB

Score : 200 points

Problem Statement

Joisino is about to compete in the final round of a certain programming competition. In this contest, there are N problems, numbered1 through N. Joisino knows that it takes her Ti seconds to solve problem i(1≦iN).

Also, there are M kinds of drinks offered to the contestants, numbered 1 through M. If Joisino takes drink i(1≦iM), her brain will be stimulated and the time it takes for her to solve problem Pi will become Xi seconds. It does not affect the time to solve the other problems.

A contestant is allowed to take exactly one of the drinks before the start of the contest. For each drink, Joisino wants to know how many seconds it takes her to solve all the problems if she takes that drink. Here, assume that the time it takes her to solve all the problems is equal to the sum of the time it takes for her to solve individual problems. Your task is to write a program to calculate it instead of her.

Constraints

  • All input values are integers.
  • 1≦N≦100
  • 1≦Ti≦105
  • 1≦M≦100
  • 1≦PiN
  • 1≦Xi≦105

Input

The input is given from Standard Input in the following format:

N
T1 T2 … TN
M
P1 X1
P2 X2
:
PM XM

Output

For each drink, calculate how many seconds it takes Joisino to solve all the problems if she takes that drink, and print the results, one per line.


Sample Input 1

Copy
3
2 1 4
2
1 1
2 3

Sample Output 1

Copy
6
9

If Joisino takes drink 1, the time it takes her to solve each problem will be 1, 1 and 4 seconds, respectively, totaling 6 seconds.

If Joisino takes drink 2, the time it takes her to solve each problem will be 2, 3 and 4 seconds, respectively, totaling 9 seconds.


Sample Input 2

Copy
5
7 2 3 8 5
3
4 2
1 7
4 13

Sample Output 2

Copy
19
25
30
题意:告诉你原始的做题时间,现在可以喝饮料,改变对应一个题的做题时间,问按顺序喝饮料,求总的做题时间(每次喝饮料都不影响上下数据,依次独立)
解法:模拟
#include
using namespace std;
long long n,m;
long long t[100010];
long long p;
struct P
{
    long long x,y;
}He[100010];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>t[i];
    }
    cin>>m;
    for(int i=1;i<=m;i++)
    {
        cin>>He[i].x>>He[i].y;
    }
    for(int i=1;i<=m;i++)
    {
        long long sum=0;
        for(int j=1;j)
        {
            sum+=t[j];
         //   cout<
        }
        sum+=He[i].y;
       // cout<
        for(int j=He[i].x+1;j<=n;j++)
        {
            sum+=t[j];
         //   cout<
        }
        cout<endl;
    }
    return 0;
}

C - Lining Up


Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

There are N people, conveniently numbered 1 through N. They were standing in a row yesterday, but now they are unsure of the order in which they were standing. However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person. According to their reports, the difference above for person i is Ai.

Based on these reports, find the number of the possible orders in which they were standing. Since it can be extremely large, print the answer modulo 109+7. Note that the reports may be incorrect and thus there may be no consistent order. In such a case, print 0.

Constraints

  • 1≦N≦105
  • 0≦AiN−1

Input

The input is given from Standard Input in the following format:

N
A1 A2 … AN

Output

Print the number of the possible orders in which they were standing, modulo 109+7.


Sample Input 1

Copy
5
2 4 4 0 2

Sample Output 1

Copy
4

There are four possible orders, as follows:

  • 2,1,4,5,3
  • 2,5,4,1,3
  • 3,1,4,5,2
  • 3,5,4,1,2

Sample Input 2

Copy
7
6 4 0 2 4 0 2

Sample Output 2

Copy
0

Any order would be inconsistent with the reports, thus the answer is 0.


Sample Input 3

Copy
8
7 5 1 1 7 3 5 3

Sample Output 3

Copy
16
题意:没读懂
解法:首先判断不成立的,当然是出现数字三次以上就算不合法(0不能出现两次以上),然后统计每个数字出现两次的数量,求2^n%mod即可
#include
using namespace std;
long long n;
map<long long,long long>q;
map<long long,long long>::iterator it;
long long  modl(long long a, long long b, long long c)        //快速幂取余a^b%c
{
    long long res, t;
    res = 1 % c;
    t = a % c;
    while (b)
    {
        if (b & 1)
        {
            res = res * t % c;
        }
        t = t * t % c;
        b >>= 1;
    }
    return res;
}
long long mod=1e9+7;
int main()
{
    q.clear();
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        long long num;
        cin>>num;
        q[num]++;
    }
    if(q[0]>1)
    {
        cout<<"0"<<endl;
    }
    else if(q[0]==1||q[0]==0)
    {
        int num=0;
        for(it=q.begin();it!=q.end();it++)
        {
            if(it->second==2)
            {
                num++;
            }
            else if(it->second>2)
            {
                cout<<"0"<<endl;
                return 0;
            }
        }
        num%=mod;
        cout<2,num,mod)%mod<<endl;
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/yinghualuowu/p/6196089.html

你可能感兴趣的:(AtCoder Beginner Contest 050 ABC题)