AtCoder Beginner Contest 099 解题报告

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 ABC001ABC002 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: ABD001ABD002ABD999.

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

  • 1N1998
  • 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

Copy
999

Sample Output 1

Copy
ABC

The 999-th round of AtCoder Beginner Contest is labeled as ABC999.


Sample Input 2

Copy
1000

Sample Output 2

Copy
ABD

The 1000-th round of AtCoder Beginner Contest is labeled as ABD001.


Sample Input 3

Copy
1481

Sample Output 3

Copy
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

  • 1a<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

Copy
8 13

Sample Output 1

Copy
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

Copy
54 65

Sample Output 2

Copy
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

  • 1N100000
  • 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

Copy
127

Sample Output 1

Copy
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

Copy
3

Sample Output 2

Copy
3

By withdrawing 1 yen three times, we can withdraw 3 yen in three operations.


Sample Input 3

Copy
44852

Sample Output 3

Copy
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 1i,j,x,yN:

  • 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

  • 1N500
  • 3C30
  • 1Di,j1000(ij),Di,j=0(i=j)
  • 1ci,jC
  • 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

Copy
2 3
0 1 1
1 0 1
1 4 0
1 2
3 3

Sample Output 1

Copy
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,jDj,i is possible.


Sample Input 2

Copy
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

Copy
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;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值