【BestCoder Round #93】hdu6020 MG loves apple
来源:互联网 发布:软件测试行业 龙头 编辑:程序博客网 时间:2024/04/28 16:07
Problem Description MG is a rich boy. He has n apples, each has a
value of V(0<=V< =9).A valid number does not contain a leading zero, and these apples have
just made a valid N digit number.MG has the right to take away K apples in the sequence, he wonders if
there exists a solution: After exactly taking away K apples, the valid
N−K digit number of remaining apples mod 3 is zero.MG thought it very easy and he had himself disdained to take the job.
As a bystander, could you please help settle the problem and calculate
the answer?Input The first line is an integer T which indicates the case
number.(1<=T<=60)And as for each case, there are 2 integer N(1<=N<=100000),K(0<=K< N) in
the first line which indicate apple-number, and the number of apple
you should take away.MG also promises the sum of N will not exceed 1000000。
Then there are N integers X in the next line, the i-th integer means
the i-th gold’s value(0<=X<=9).Output As for each case, you need to output a single line.
If the solution exists, print”yes”,else print “no”.(Excluding
quotation marks)
首先知道问题等价于剩下的数字和是
扫描一遍,记下
枚举余数是
说起来很麻烦,但是代码不难写。注意特判只剩下
感觉官方题解做法很繁琐,而且有问题,比如数据
6 2
201011
当然也可能是我理解错了意思。
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;char s[100010];int a[100010],n,k;bool solve(){ int cnt0=0,cnt1=0,cnt2=0,cnt369=0,before1=0,before2=0,before369=0,sum,x,mnj,mxj; scanf("%d%d",&n,&k); scanf("%s",s+1); for (int i=1;i<=n;i++) a[i]=s[i]-'0'; for (int i=1;i<=n;i++) { if (a[i]%3==1) cnt1++; if (a[i]%3==2) cnt2++; if (a[i]%3==0) { if (!a[i]) { cnt0++; if (!cnt1) before1++; if (!cnt2) before2++; if (!cnt369) before369++; } else cnt369++; } } sum=(cnt1+cnt2*2)%3; if (k==n-1&&cnt0+cnt369) return 1; for (int i=0;i<=cnt2;i++) { x=((sum-2*i)%3+3)%3; mnj=max(0,k-i-cnt0-cnt369); mxj=min(cnt1,k-i); while (mnj%3!=x) mnj++; while (mxj>=0&&mxj%3!=x) mxj--; if (mnj>mxj) continue; if (before369<=k-i-mnj) return 1; if (mnj<cnt1&&before1<=k-i-mnj) return 1; if (i<cnt2&&before2<=k-i-mnj) return 1; } return 0;}int main(){ int T; scanf("%d",&T); while (T--) if (solve()) printf("yes\n"); else printf("no\n");}
- 【BestCoder Round #93】hdu6020 MG loves apple
- HDU6020 MG loves apple
- MG loves apple BestCoder Round #93 1002
- MG loves apple HDU6020 BC #93-1002 思维题
- 【BestCoder Round #93】HDU6019 MG loves gold
- 【BestCoder Round #93】HDU6019 MG loves gold
- BestCoder Round #93 MG loves gold hdu 6019
- hdu 6020 MG loves apple //bc Round #93 1002
- HDU 6021 MG loves string(容斥原理)——BestCoder Round #93 1003
- HDU 6020 MG loves apple
- 【STL】HDU6019MG loves gold【 BestCoder Round #93】
- Bestcoder Round#43pog loves szh II
- BestCoder Round #78 CA Loves GCD
- BestCoder Round #82 ztr loves mat
- BestCoder Round #82 ztr loves lucky numbers
- hdoj5850 NanoApe Loves Sequence BestCoder Round #86
- BestCoder Round #90 Kblack loves flag
- HDU6019 MG loves gold
- 蓝桥杯-表达式计算(java)
- java动态代理机制
- A
- Ubuntu 14.0 搭建lnmp
- 记录thinkphp5的一些坑
- 【BestCoder Round #93】hdu6020 MG loves apple
- Google Guava--ArrayListMultimap方法使用
- 使用GSOAP的笔记
- 在toupper/tolower前面加::,强制指定是C版本的
- 【蓝桥】 基础练习 十六进制转十进制
- Javaoop第一章抽象和封装
- (十)栈应用实例
- hihocoder #1496 : 寻找最大值
- VSCode通过d.ts文件获得智能提示