题目链接

 

Problem Description
MG is a rich boy. He has 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 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)
 
Sample Input
2
5 2
11230
4 2
1000
 
Sample Output
yes
no
 
题意:

HDU  6020---MG loves apple(枚举)

 

思路:

HDU  6020---MG loves apple(枚举)

 

代码如下:

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

 

 

相关文章:

  • 2021-10-05
  • 2021-09-05
  • 2021-06-20
  • 2021-05-28
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-12
  • 2021-10-09
  • 2021-10-15
  • 2021-11-25
  • 2021-12-10
相关资源
相似解决方案