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
- 1≤A,B≤1 000
- A+B≤X≤10 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
1234 150 100
Sample Output 1
84
You have 1234−150=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
1000 108 108
Sample Output 2
28
Sample Input 3
579 123 456
Sample Output 3
0
Sample Input 4
7477 549 593
Sample Output 4
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 }
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
- 0≤A,B,C≤50
- A+B+C≥1
- 50≤X≤20 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
2 2 2 100
Sample Output 1
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
5 1 0 150
Sample Output 2
0
Note that the total must be exactly X yen.
Sample Input 3
30 40 50 6000
Sample Output 3
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 (1≤i≤2, 1≤j≤N) 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
- 1≤N≤100
- 1≤Ai,j≤100 (1≤i≤2, 1≤j≤N)
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
5 3 2 2 4 1 1 2 2 2 1
Sample Output 1
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
4 1 1 1 1 1 1 1 1
Sample Output 2
5
You will always collect the same number of candies, regardless of how you travel.
Sample Input 3
7 3 3 4 5 4 5 3 5 3 4 4 2 3 2
Sample Output 3
29
Sample Input 4
1 2 3
Sample Output 4
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 }