hdu 1404 Digital Deletions

來源:互聯網
上載者:User

這題我先建了表來做的。

可以進行兩個操作:

1、把其中一個數變為比它小的數;

2、把其中一個數字0及其右邊的所以數字刪除。
兩人輪流進行操作,

//Time 281ms, Memory 4140
#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int maxn=1000000;int sg[maxn]={0};int len(int n){    if(n/100000) return 6;    if(n/10000) return 5;    if(n/1000) return 4;    if(n/100) return 3;    if(n/10) return 2;    return 1;}void mex(int n){    int l=len(n);    for(int i=l;i>0;i--)  //1、把其中一個數變為比它小的數;    {        int m=1;        for(int j=1;j<i;j++) m*=10;        int t=(n%(m*10))/m;        for(j=1;j<=9-t;j++) sg[n+m*j]=1;    }    if(l<6)   //2、把其中一個數字0及其右邊的所以數字刪除。    {        int m=n,a=1;        for(int i=1;i<=6-l;i++)        {            m*=10;            for(int j=0;j<a;j++)            {                sg[m+j]=1;            }            a*=10;        }    }}void f(){    sg[0]=1;    for(int i=1;i<maxn;i++) if(!sg[i])  // 這方法與素數篩選法有異曲同工之妙。    {        mex(i);    }}int main(){    int l,n;    char s[7];    f();    while(scanf("%s",s)!=EOF)    {        if(s[0]=='0')        {            printf("Yes\n");continue;        }        l=strlen(s);        n=s[0]-'0';        for(int i=1;i<l;i++) n=n*10+s[i]-'0';        if(sg[n]) printf("Yes\n");        else printf("No\n");    }    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.