HDU 6020---MG loves apple(枚举)
2018-06-17 22:54:06来源:未知 阅读 ()
题目链接
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?
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).
If the solution exists, print”yes”,else print “no”.(Excluding quotation marks)
思路:
代码如下:
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> using namespace std; int a[100005]; char s[100005]; void cal(int &a3, int &E1,int &E2,int N) { a3=0; E1=0; E2=0; for(int i=1;i<=N;i++) { if(a[i]==3) break; if(a[i]==0) a3++; } for(int i=1;i<=N;i++) { if(a[i]==0) break; if(a[i]==1) E1=1; if(a[i]==2) E2=1; } return ; } int main() { int T; cin>>T; while(T--) { int N,K; int s1=0,s2=0,s3=0; scanf("%d%d",&N,&K); scanf("%s",s+1); for(int i=1;i<=N;i++) { a[i]=s[i]-'0'; if(a[i]%3==1) a[i]=1,s1++; else if(a[i]%3==2) a[i]=2,s2++; else s3++,a[i]=(a[i])?3:0; } int ans=(s1+s2*2)%3; int a3,E1,E2,f=0; cal(a3,E1,E2,N); for(int C=0;C<=s2&&C<=K;C++) ///C->2; B->1; A->0; { int B=((ans-C*2)%3+3)%3; for(;B<=s1&&C+B<=K;B=B+3) { int A=K-C-B; if(A<=s3) { if(A>a3) f=1; else if(B<s1&&E1) f=1; else if(C<s2&&E2) f=1; if(f) break; } } if(f) break; } if((N==K+1)&&s3) f=1; if(f) puts("yes"); else puts("no"); } return 0; }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:1506 传话
下一篇:C++中进制转换问题
- bzoj3569 DZY Loves Chinese II 2020-05-25
- HDU-2955-Robberies(0-1背包) 2020-03-30
- hdu1455 拼木棍(经典dfs) 2020-02-29
- anniversary party_hdu1520 2020-02-16
- hdu1062 text reverse 2020-01-27
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash