AtCoder Beginner Contest 087 (ABC)

A - Buying Sweets

题目链接:https://abc087.contest.atcoder.jp/tasks/abc087_a

Time limit : 2sec / Memory limit : 256MB

Score : 100 points

Problem Statement

You went shopping to buy cakes and donuts with X yen (the currency of Japan).

First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop.

How much do you have left after shopping?

Constraints

  • 1A,B1 000
  • A+BX10 000
  • X, A and B are integers.

Input

Input is given from Standard Input in the following format:

X
A
B

Output

Print the amount you have left after shopping.


Sample Input 1

Copy
1234
150
100

Sample Output 1

Copy
84

You have 1234150=1084 yen left after buying a cake. With this amount, you can buy 10 donuts, after which you have 84 yen left.


Sample Input 2

Copy
1000
108
108

Sample Output 2

Copy
28

Sample Input 3

Copy
579
123
456

Sample Output 3

Copy
0

Sample Input 4

Copy
7477
549
593

Sample Output 4

Copy
405
 1     #include<bits/stdc++.h>
 2     using namespace std;
 3      
 4     int main()
 5     {
 6         int x,a,b;
 7         while(cin>>x>>a>>b){
 8             x-=a;
 9             x%=b;
10             cout<<x<<endl;
11         }
12         return 0;
13     }
View Code

B - Coins

题目链接:https://abc087.contest.atcoder.jp/tasks/abc087_b

Time limit : 2sec / Memory limit : 256MB

Score : 200 points

Problem Statement

You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total?

Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.

Constraints

  • 0A,B,C50
  • A+B+C1
  • 50X20 000
  • A, B and C are integers.
  • X is a multiple of 50.

Input

Input is given from Standard Input in the following format:

A
B
C
X

Output

Print the number of ways to select coins.


Sample Input 1

Copy
2
2
2
100

Sample Output 1

Copy
2

There are two ways to satisfy the condition:

  • Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.
  • Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.

Sample Input 2

Copy
5
1
0
150

Sample Output 2

Copy
0

Note that the total must be exactly X yen.


Sample Input 3

Copy
30
40
50
6000

Sample Output 3

Copy
213

题解:找零钱
 1     #include<bits/stdc++.h>
 2     using namespace std;
 3      
 4     int main()
 5     {
 6         int x,a,b,c;
 7         while(cin>>a>>b>>c>>x){
 8             x/=50;
 9             int sum=0;
10             for(int i=0;i<=a;i++){
11                 for(int j=0;j<=b;j++){
12                     for(int k=0;k<=c;k++){
13                         if(i*10+j*2+k==x) sum++;
14                     }
15                 }
16             }
17             cout<<sum<<endl;
18         }
19         return 0;
20     }

C - Candies

题目链接:https://abc087.contest.atcoder.jp/tasks/arc090_a

Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

We have a 2×N grid. We will denote the square at the i-th row and j-th column (1i2, 1jN) as (i,j).

You are initially in the top-left square, (1,1). You will travel to the bottom-right square, (2,N), by repeatedly moving right or down.

The square (i,j) contains Ai,j candies. You will collect all the candies you visit during the travel. The top-left and bottom-right squares also contain candies, and you will also collect them.

At most how many candies can you collect when you choose the best way to travel?

Constraints

  • 1N100
  • 1Ai,j100 (1i2, 1jN)

Input

Input is given from Standard Input in the following format:

N
A1,1 A1,2  A1,N
A2,1 A2,2  A2,N

Output

Print the maximum number of candies that can be collected.


Sample Input 1

Copy
5
3 2 2 4 1
1 2 2 2 1

Sample Output 1

Copy
14

The number of collected candies will be maximized when you:

  • move right three times, then move down once, then move right once.

Sample Input 2

Copy
4
1 1 1 1
1 1 1 1

Sample Output 2

Copy
5

You will always collect the same number of candies, regardless of how you travel.


Sample Input 3

Copy
7
3 3 4 5 4 5 3
5 3 4 4 2 3 2

Sample Output 3

Copy
29

Sample Input 4

Copy
1
2
3

Sample Output 4

Copy
5

题解:分成两个数组 同时使用前缀和 取最大值
 1     #include<bits/stdc++.h>
 2     using namespace std;
 3     int a[101],b[101];
 4     int suma[101],sumb[101];
 5     int main()
 6     {
 7         int n;
 8         while(cin>>n){
 9             for(int i=0;i<n;i++){
10                 cin>>a[i];
11             }
12             for(int i=0;i<n;i++){
13                 cin>>b[i];
14             }
15             suma[0]=a[0];sumb[0]=b[0];
16             for(int i=1;i<n;i++){
17                 suma[i]=suma[i-1]+a[i];
18                 sumb[i]=sumb[i-1]+b[i];
19             }
20             int maxn=suma[0]+sumb[n-1];
21             for(int i=1;i<n;i++){
22                 int sum=suma[i]+sumb[n-1]-sumb[i-1];
23                 maxn=max(maxn,sum);
24             }
25             cout<<maxn<<endl;
26         }
27         return 0;
28     }


原文地址:https://www.cnblogs.com/wydxry/p/8492592.html