天天看点

P2953 [USACO09OPEN]Cow Digit Game S

题目:

#include <bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int f[N];
int ma(int x)
{
    int ans=0;
    while(x)
    {
        int d=x%10;
        ans=max(ans, d);
        x/=10;
    }
    return ans;
}
int mi(int x)
{
    int ans=10;
    while(x)
    {
        int d=x%10;
        if(d) ans=min(ans, d);
        x/=10;
    }
    return ans;
}
void init()
{
    for(int i=1; i<=9; i++) f[i]=1;

    for(int i=0; i<N; i ++ )
    {
        if(!f[i-ma(i)] || !f[i-mi(i)]) f[i]=1;
    }
}
int main()
{
    init();
    int t;
    cin >> t;
    while(t -- )
    {
        long long n;
        cin >> n;
        if(f[n]) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}      

继续阅读