【博弈论】【SG函数】bzoj3404 [Usaco2009 Open]Cow Digit Game又见数字游戏
#include<cstring> #include<cstdio> #include<algorithm> #include<set> using namespace std; int m,n; int SG[1000001]; int sg(int x) { if(SG[x]!=-1) return SG[x]; if(!x) return SG[x]=0; set<int>S; int maxv=0,minv=2147483647; int t=x; while(t) { if(t%10) { maxv=max(t%10,maxv); minv=min(t%10,minv); } t/=10; } S.insert(sg(x-maxv)); S.insert(sg(x-minv)); for(int i=0;;++i) if(S.find(i)==S.end()) return SG[x]=i; } int main() { scanf("%d",&m); memset(SG,-1,sizeof(SG)); for(;m;--m) { scanf("%d",&n); puts(sg(n)?"YES":"NO"); } return 0; }
——The Solution By AutSky_JadeK From UESTC
转载请注明出处:http://www.cnblogs.com/autsky-jadek/