zoukankan      html  css  js  c++  java
  • hdu 6020 MG loves apple 恶心模拟

    题目链接:点击传送

    MG loves apple

    Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)



    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 NK 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)
     
    Sample Input
    2 5 2 11230 4 2 1000
     
    Sample Output
    yes no
     
    Source
    思路:枚举以i+1为起点的,去掉前i个,后面的需要去掉k-i个,进行check()
    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<set>
    #include<map>
    using namespace std;
    #define ll long long
    #define pi (4*atan(1.0))
    #define eps 1e-14
    #define bug(x)  cout<<"bug"<<x<<endl;
    const int N=1e5+10,M=1e6+10,inf=2147483647;
    const ll INF=1e18+10,mod=2147493647;
    int num[N][5];
    int check0(int a,int x,int y,int z)
    {
        if(a<0||x<0||y<0||z<0)return 0;
        int ans=0;
        if(x>=1&&y>=1&&z>=2)
        {
            int xx=x,yy=y,zz=z;
            xx-=1;yy-=1;zz-=2;
            int l=(xx/3+yy/3);
            zz-=min(zz/3,l)*3;
            if(zz<=a)ans=1;
        }
        if(x>=2&&y>=2&&z>=4)
        {
            int xx=x,yy=y,zz=z;
            xx-=2;yy-=2;zz-=4;
            int l=(xx/3+yy/3);
            zz-=min(zz/3,l)*3;
            if(zz<=a)ans=1;
        }
        int xx=x,yy=y,zz=z;
        int l=(xx/3+yy/3);
        zz-=min(zz/3,l)*3;
        if(zz<=a)ans=1;
        return ans;
    }
    int check1(int a,int x,int y,int z)
    {
        return max(check0(a,x-1,y,z-1),check0(a,x,y-2,z-2));
    }
    int check2(int a,int x,int y,int z)
    {
        return max(check0(a,x,y-1,z-1),check0(a,x-2,y,z-2));
    }
    char a[N];
    int main()
    {
        int T;
        scanf("%d",&T);
        while(T--)
        {
            memset(num,0,sizeof(num));
            int n,K;
            scanf("%d%d",&n,&K);
            scanf("%s",a+1);
            if(K==n-1)
            {
                int mmp=0;
                for(int i=1;i<=n;i++)
                if(a[i]%3==0)mmp=1;
                if(mmp)printf("yes
    ");
                else printf("no
    ");
                continue;
            }
            int sum=0;
            for(int i=1;i<=n;i++)
                sum+=a[i]-'0';
            int x=sum%3;
            for(int i=n;i>=1;i--)
            {
                int x=(a[i]-'0')%3;
                num[i][0]=num[i+1][0];
                num[i][1]=num[i+1][1];
                num[i][2]=num[i+1][2];
                num[i][x]++;
            }
            int ans=0;
            /// 枚举以i+1为起点的,去掉前i个,后面的需要去掉k-i个,进行check()
            for(int i=0;i<=K;i++)
            {
                if(a[i+1]=='0')continue;
                if(x==1)ans=max(ans,check1(num[i+2][0],num[i+2][1],num[i+2][2],K-i));
                else if(x==2)ans=max(ans,check2(num[i+2][0],num[i+2][1],num[i+2][2],K-i));
                else ans=max(ans,check0(num[i+2][0],num[i+2][1],num[i+2][2],K-i));
                x-=a[i+1]-'0';
                x=(x%3+3)%3;
            }
            if(ans)
                printf("yes
    ");
            else
                printf("no
    ");
        }
        return 0;
    }
     
  • 相关阅读:
    关于Git的使用方法
    Python读取Excel数据
    用到的Dos命令总结 持续更新
    windows下使用Jenkins+Gitea持续集成
    HDFS概述(2)————Block块大小设置
    分布式文件系统比较出名的有HDFS  和 GFS
    c++里面有没有什么办法做到 判断某个给定的未知数是double类型还是int类型 呢?
    About HDFS blocks
    hadoop深入学习之SequenceFile
    使用RawComparator加速Hadoop程序
  • 原文地址:https://www.cnblogs.com/jhz033/p/6659029.html
Copyright © 2011-2022 走看看