A - ABD
Time limit : 2sec / Memory limit : 256MB
Score : 100 points
Problem Statement
Decades have passed since the beginning of AtCoder Beginner Contest.
The contests are labeled as ABC001
, ABC002
, … from the first round, but after the 999-th round ABC999
, a problem occurred: how the future rounds should be labeled?
In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: ABD001
, ABD002
, …, ABD999
.
You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
Constraints
- 1≤N≤1998
- N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.
Sample Input 1
999
Sample Output 1
ABC
The 999-th round of AtCoder Beginner Contest is labeled as ABC999
.
Sample Input 2
1000
Sample Output 2
ABD
The 1000-th round of AtCoder Beginner Contest is labeled as ABD001
.
Sample Input 3
1481
Sample Output 3
ABD
The 1481-th round of AtCoder Beginner Contest is labeled as ABD482
.
实在是不想复习了 ......
/**
简单的一个输入输出问题
*/
#include<bits/stdc++.h>
using namespace std;
int main (){
int n;scanf("%d",&n);
if(n<=999) puts("ABC");
else puts("ABD");
return 0;
}
B - Stone Monument
Time limit : 2sec / Memory limit : 256MB
Score : 200 points
Problem Statement
In some village, there are 999 towers that are 1,(1+2),(1+2+3),…,(1+2+3+…+999) meters high from west to east, at intervals of 1 meter.
It had been snowing for a while before it finally stopped. For some two adjacent towers located 1 meter apart, we measured the lengths of the parts of those towers that are not covered with snow, and the results are a meters for the west tower, and b meters for the east tower.
Assuming that the depth of snow cover and the altitude are the same everywhere in the village, find the amount of the snow cover.
Assume also that the depth of the snow cover is always at least 1 meter.
Constraints
- 1≤a<b<499500(=1+2+3+…+999)
- All values in input are integers.
- There is no input that contradicts the assumption.
Input
Input is given from Standard Input in the following format:
a b
Output
If the depth of the snow cover is x meters, print x as an integer.
Sample Input 1
8 13
Sample Output 1
2
The heights of the two towers are 10 meters and 15 meters, respectively. Thus, we can see that the depth of the snow cover is 2 meters.
Sample Input 2
54 65
Sample Output 2
1
/**
相邻塔的积雪之差是不变的即为相邻塔的高度差
直接算出b的高度然后作差即是ans
*/
#include<bits/stdc++.h>
using namespace std;
int main (){
int l,r;cin>>l>>r;
int diff=r-l;
int tmp=(diff+1)*diff/2;
tmp=tmp-r;
cout<<tmp<<endl;
return 0;
}
C - Strange Bank
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:
1 yen (the currency of Japan)
6 yen, 62(=36) yen, 63(=216) yen, ...
9 yen, 92(=81) yen, 93(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.
Constraints
- 1≤N≤100000
- N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
If at least x operations are required to withdraw exactly N yen in total, print x.
Sample Input 1
127
Sample Output 1
4
By withdrawing 1 yen, 9 yen, 36(=62) yen and 81(=92) yen, we can withdraw 127 yen in four operations.
Sample Input 2
3
Sample Output 2
3
By withdrawing 1 yen three times, we can withdraw 3 yen in three operations.
Sample Input 3
44852
Sample Output 3
16
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+7;
int dp[maxn];
int a[maxn];
int main (){
int tmp=6,cnt=0;
a[cnt++]=1;
while(tmp<=100000){
a[cnt++]=tmp;
tmp*=6;
}
tmp=9;
while(tmp<=100000){
a[cnt++]=tmp;
tmp*=9;
}
sort(a,a+cnt);
int n;cin>>n;
memset(dp,0x3f3f3f3f,(n+3)*sizeof(int));
dp[0]=0;
for(int i=0;i<cnt;i++){
for(int j=a[i];j<=n;j++)
dp[j]=min(dp[j],dp[j-a[i]]+1);
}
cout<<dp[n]<<endl;
return 0;
}
D - Good Grid
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left.
These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color ci,j.
We say the grid is a good grid when the following condition is met for all i,j,x,y satisfying 1≤i,j,x,y≤N:
- If (i+j)%3=(x+y)%3, the color of (i,j) and the color of (x,y) are the same.
- If (i+j)%3≠(x+y)%3, the color of (i,j) and the color of (x,y) are different.
Here, X%Y represents X modulo Y.
We will repaint zero or more squares so that the grid will be a good grid.
For a square, the wrongness when the color of the square is X before repainting and Y after repainting, is DX,Y.
Find the minimum possible sum of the wrongness of all the squares.
Constraints
- 1≤N≤500
- 3≤C≤30
- 1≤Di,j≤1000(i≠j),Di,j=0(i=j)
- 1≤ci,j≤C
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N C D1,1 … D1,C : DC,1 … DC,C c1,1 … c1,N : cN,1 … cN,N
Output
If the minimum possible sum of the wrongness of all the squares is x, print x.
Sample Input 1
2 3 0 1 1 1 0 1 1 4 0 1 2 3 3
Sample Output 1
3
- Repaint (1,1) to Color 2. The wrongness of (1,1) becomes D1,2=1.
- Repaint (1,2) to Color 3. The wrongness of (1,2) becomes D2,3=1.
- Repaint (2,2) to Color 1. The wrongness of (2,2) becomes D3,1=1.
In this case, the sum of the wrongness of all the squares is 3.
Note that Di,j≠Dj,i is possible.
Sample Input 2
4 3 0 12 71 81 0 53 14 92 0 1 1 2 1 2 1 1 2 2 2 1 3 1 1 2 2
Sample Output 2
428
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
int n,c;
cin>>n>>c;
int a[3][34];
int d[34][34];
for(int i=0;i<34;i++){
a[0][i]=0;a[1][i]=0;a[2][i]=0;
}
for(int i=1;i<=c;i++){
for(int j=1;j<=c;j++){
cin>>d[i][j];
}
}
int tmp;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>tmp;
for(int k=1;k<=c;k++){
a[(i+j)%3][k]+=d[tmp][k];
}
}
}
int mini=INT_MAX;
for(int i=1;i<=c;i++){
for(int j=1;j<=c;j++){
if(i==j)continue;
for(int k=1;k<=c;k++){
if(i==k||j==k)continue;
mini=min(mini,a[0][i]+a[1][j]+a[2][k]);
}
}
}
cout<<mini<<endl;
return 0;
}