Codeforces Round #698 (Div. 2) (思维)

A. Nezzar and Colorful Balls


题意:给你一个非递减序列的球,现在要给每个球涂色,要求每种颜色的球的值是单调递增的,问最少用多少种颜色
 
解题思路:根据题意,我们不难看出相同权值的小球不可能为同一颜色,我们只需要找到权值相同且数量最多的小球的数量就行,由于球的权值是非递减的,换句话说权值相同的球是挨在一起的,我们只需要判断连续的相同的球的数量最大是多少就行
Code:

#include<bits/stdc++.h>
using namespace std;
int a[105];
int main()
{
	int t,n;
	scanf("%d",&t);
	while(t--) {
		scanf("%d",&n);
		for(int i = 1;i <= n; ++i) scanf("%d",&a[i]);
		a[0] = a[1];
		int ans = 1;
		int loc = 0,lock = a[1];
		for(int i = 1;i <= n; ++i) {
			if(a[i] == lock)
				loc++;
			else {
				loc = 1;
				lock = a[i];
			}
			ans = max(ans,loc);
		}
		printf("%d\n",ans);
	}
	return 0;
}

B. Nezzar and Lucky Number


题意:判断是否有由一个或者多个包含幸运的数字d的数组成a[i],这个幸运数字d选取[1,9]
 
解题思路:很明显当\(a[i] >= 10\times d\)时,一定存在,否则我们就分类讨论,详情请看代码,(代码由些许暴力)
Code:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll t,q,d;
 
int main()
{
	ll k;
	scanf("%lld",&t);
	while(t--) {
		scanf("%lld%lld",&q,&d);
		for(int i = 0;i < q; ++i) {
			scanf("%lld",&k);
			ll kk = k % 10;
			if(k >= d * 10LL) {
				puts("YES");
			}
			else {
				if(d == 1)
					puts("YES");
				else if(d == 2) {
					if(k % 2 == 0)
						puts("YES");
					else
						puts("NO");
				}
				else if(d == 3) {
					if(kk == 3 || kk == 6 || kk == 9 || (k >= 12 && kk == 2) || (k >= 15 && kk == 5) || (k >= 18 && kk == 8) || (k >= 21 && kk == 1) || (k >= 24 && kk == 4) || (k >= 27 && kk == 7) || (k >= 30 && kk == 0))
						puts("YES");
					else
						puts("NO");
				}
				else if(d == 4) {
					if(kk == 4 || kk == 8 || (k >= 12 && kk == 2)|| (k >= 16 && kk == 6) || (k >= 20 && kk == 0))
						puts("YES");
					else
						puts("NO");
				}
				else if(d == 5) {
					if(kk == 0 || kk == 5)
						puts("YES");
					else
						puts("NO");
				}
				else if(d == 6) {
					if(kk == 6 || (k >= 12 && kk == 2) || (k >= 18 && kk == 8) || (k >= 24 && kk == 4) || (k >= 30 && kk == 0))
						puts("YES");
					else
						puts("NO");
				}
				else if(d == 7) {
					if(kk == 7 || (k >= 14 && kk == 4) || (k >= 21 && kk == 1) || (k >= 28 && kk == 8) || (k >= 35 && kk == 5) || (k >= 42 && kk == 2) || (k >= 49 && kk == 9) || (k >= 56 && kk == 6) || (k >= 63 && kk == 3) || (k >= 70 && kk == 0))
						puts("YES");
					else
						puts("NO");
				}
				else if(d == 8) {
					if(kk == 8 || (k >= 16 && kk == 6) || (k >= 24 && kk == 4) || (k >= 32 && kk == 2) || (k >= 40 && kk == 0))
						puts("YES");
					else
						puts("NO");
				}
				else if(d == 9) {
					if(kk == 9 || (k >= 18 && kk == 8) || (k >= 27 && kk == 7) || (k >= 36 && kk == 6) || (k >= 45 && kk == 5) || (k >= 54 && kk == 4) || (k >= 63 && kk == 3) || (k >= 72 && kk == 2) || (k >= 81 && kk == 1) || (k >= 90 && kk == 0))
						puts("YES");
					else
						puts("NO");
				}
			}
		}
	}
	
	return 0;
}

看到一个神奇的代码:

main(q,d,x){for(scanf("%*d");~scanf("%d%d",&q,&d);)while(q--){
scanf("%d",&x);while(x>d&&x<d*10&&x%d)x-=10;puts(x<d?"NO":"YES");}}
posted @ 2021-01-30 00:10  MangataTS  阅读(71)  评论(0编辑  收藏  举报