[bzoj3404] [Usaco2009 Open] Cow Digit game again see number games

Source: Internet
Author: User

Just calculate the SG value of all the numbers.

1#include <cstdio>2#include <iostream>3#include <cstring>4#include <algorithm>5 using namespacestd;6 Const intmaxn=1002333;7 intSG[MAXN];8 intst[8];9 inti,j,k,n,m;Ten   One intRaCharRx; AInlineintRead () { -Rx=getchar (), ra=0; -      while(rx<'0'|| Rx>'9') rx=GetChar (); the      while(rx>='0'&&rx<='9') ra*=Ten, ra+=rx- -, Rx=getchar ();returnRA; - } - intMain () { -sg[0]=0;intmx,mn; +      for(i=1; i<=1000000; i++){ -mx=0, mn=Ten; +          for(k=i;k;k/=Ten){ Aj=k%Ten; at             if(j>0&AMP;&AMP;J&LT;MN) mn=J; -             if(J&GT;MX) mx=J; -         } -         if(MX==MN) sg[i]=!sg[i-MX]; -         Else if(Sg[i-mx]&&sg[i-mn]) sg[i]=0; -         Else if(sg[i-mx]!=1&&sg[i-mn]!=1) sg[i]=1; in         Elsesg[i]=2; -     } to      for(intT=read (); T t--) +Puts (Sg[read ())?"YES":"NO"); -}
View Code

[bzoj3404] [Usaco2009 Open] Cow Digit game again see number games

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.