AtCoder Beginner Contest 088 (ABC)
A - Infinite Coins
题目链接:https://abc088.contest.atcoder.jp/tasks/abc088_a
Time limit : 2sec / Memory limit : 256MB
Score: 100 points
Problem Statement
E869120 has A 1-yen coins and infinitely many 500-yen coins.
Determine if he can pay exactly N yen using only these coins.
Constraints
- N is an integer between 1 and 10000 (inclusive).
- A is an integer between 0 and 1000 (inclusive).
Input
Input is given from Standard Input in the following format:
N A
Output
If E869120 can pay exactly N yen using only his 1-yen and 500-yen coins, print Yes
; otherwise, print No
.
Sample Input 1
2018 218
Sample Output 1
Yes
We can pay 2018 yen with four 500-yen coins and 18 1-yen coins, so the answer is Yes
.
Sample Input 2
2763 0
Sample Output 2
No
When we have no 1-yen coins, we can only pay a multiple of 500 yen using only 500-yen coins. Since 2763 is not a multiple of 500, we cannot pay this amount.
Sample Input 3
37 514
Sample Output 3
Yes
1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 int n,a; 6 while(cin>>n>>a){ 7 int s=n%500; 8 if(s<=a){ 9 cout<<"Yes"<<endl; 10 } 11 else cout<<"No"<<endl; 12 } 13 return 0; 14 }
B - Card Game for Two
题目链接:https://abc088.contest.atcoder.jp/tasks/abc088_b
Time limit : 2sec / Memory limit : 256MB
Score: 200 points
Problem Statement
We have N cards. A number ai is written on the i-th card.
Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.
The game ends when all the cards are taken by the two players, and the
score of each player is the sum of the numbers written on the cards
he/she has taken. When both players take the optimal strategy to
maximize their scores, find Alice's score minus Bob's score.
Constraints
- N is an integer between 1 and 100 (inclusive).
- ai (1≤i≤N) is an integer between 1 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
N a1 a2 a3 … aN
Output
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.
Sample Input 1
2 3 1
Sample Output 1
2
First, Alice will take the card with 3. Then, Bob will take the card with 1. The difference of their scores will be 3 - 1 = 2.
Sample Input 2
3 2 7 4
Sample Output 2
5
First, Alice will take the card with 7. Then, Bob will take the card with 4. Lastly, Alice will take the card with 2. The difference of their scores will be 7 - 4 + 2 = 5. The difference of their scores will be 3 - 1 = 2.
Sample Input 3
4 20 18 2 18
Sample Output 3
18
1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 int a[101]; 5 6 bool cmp(int x,int y) 7 { 8 return x>y; 9 } 10 11 int main() 12 { 13 int n; 14 while(cin>>n){ 15 for(int i=0;i<n;i++){ 16 cin>>a[i]; 17 } 18 sort(a,a+n,cmp); 19 int sum1=0,sum2=0; 20 for(int i=0;i<n;i++){ 21 if(i%2==0) sum1+=a[i]; 22 else sum2+=a[i]; 23 } 24 cout<<sum1-sum2<<endl; 25 } 26 return 0; 27 }
C - Takahashi's Information
题目链接:https://abc088.contest.atcoder.jp/tasks/abc088_c
Time limit : 2sec / Memory limit : 256MB
Score: 300 points
Problem Statement
We have a 3×3 grid. A number ci,j is written in the square (i,j), where (i,j) denotes the square at the i-th row from the top and the j-th column from the left.
According to Takahashi, there are six integers a1,a2,a3,b1,b2,b3 whose values are fixed, and the number written in the square (i,j) is equal to ai+bj.
Determine if he is correct.
Constraints
- ci,j (1≤i≤3,1≤j≤3) is an integer between 0 and 100 (inclusive).
Input
Input is given from Standard Input in the following format:
c1,1 c1,2 c1,3 c2,1 c2,2 c2,3 c3,1 c3,2 c3,3
Output
If Takahashi's statement is correct, print Yes
; otherwise, print No
.
Sample Input 1
1 0 1 2 1 2 1 0 1
Sample Output 1
Yes
Takahashi is correct, since there are possible sets of integers such as: a1=0,a2=1,a3=0,b1=1,b2=0,b3=1.
Sample Input 2
2 2 2 2 1 2 2 2 2
Sample Output 2
No
Takahashi is incorrect in this case.
Sample Input 3
0 8 8 0 8 8 0 8 8
Sample Output 3
Yes
Sample Input 4
1 8 6 2 9 7 0 7 7
Sample Output 4
No
题解:求和然后去掉正对角线的元素 剩下的是正对角线元素的两倍
1 #include <bits/stdc++.h> 2 using namespace std; 3 int a[3][3]; 4 int main() 5 { 6 int sum=0,sum1=0; 7 for(int i=0;i<3;i++){ 8 for(int j=0;j<3;j++){ 9 cin>>a[i][j]; 10 sum+=a[i][j]; 11 if(i==j) sum1+=a[i][j]; 12 } 13 } 14 if(sum-sum1==2*sum1) cout<<"Yes"<<endl; 15 else cout<<"No"<<endl; 16 return 0; 17 }