Topic links
problem DescriptionMG is a rich boy. He hasNApples, each with a value of V (0<=V<=9 ).
A valid number does not contain a leading zero, and these apples has just made a validNDigit number.
MG have the right and take awayKApples in the sequence, he wonders if there exists a solution:after exactly taking awayKApples, the validN−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 do you have help settle the problem and calculate the answer?
InputThe first line was an integerTWhich indicates the case number. (1<=T<= )
And as for each case, there is2Integern(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 ofNwould not exceed1000000。
Then there isn integers < Span id= "mathjax-span-74" class= "math" > x in the next line, the i-th integer means the i-th gold ' s value (< Span id= "mathjax-span-79" class= "mn" >0<= x<= 9 ).
OutputAs for each case, you need to output a.
If the solution exists, print "yes", else print "no". (excluding quotation marks)
Sample Input25 2112304 21000
Sample OutputYesno Test Instructions:
Ideas:
The code is as follows:
#include <iostream>#include<algorithm>#include<cstring>#include<cstdio>using namespacestd;inta[100005];Chars[100005];voidCalint&A3,int&e1,int&e2,intN) {A3=0; e1=0; E2=0; for(intI=1; i<=n;i++) { if(a[i]==3) Break; if(a[i]==0) a3++; } for(intI=1; i<=n;i++) { if(a[i]==0) Break; if(a[i]==1) e1=1; if(a[i]==2) e2=1; } return ;}intMain () {intT; CIN>>u; while(t--) { intn,k; ints1=0, s2=0, s3=0; scanf ("%d%d",&n,&K); scanf ("%s", s+1); for(intI=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++; ElseS3++,a[i]= (A[i])?3:0; } intAns= (s1+s2*2)%3; inta3,e1,e2,f=0; Cal (A3,e1,e2,n); for(intC=0; c<=s2&&c<=k; C + +)///c->2; b->1; a->0; { intB= ((ans-c*2)%3+3)%3; for(; b<=s1&&c+b<=k; b=b+3) { inta=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"); ElsePuts"No"); } return 0;}
HDU 6020---MG loves apple (enumeration)