hdu-1404-博弈+打表

Digital Deletions

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3312    Accepted Submission(s): 1194


Problem Description
Digital deletions is a two-player game. The rule of the game is as following. 

Begin by writing down a string of digits (numbers) that's as long or as short as you like. The digits can be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and appear in any combinations that you like. You don't have to use them all. Here is an example:



On a turn a player may either:
Change any one of the digits to a value less than the number that it is. (No negative numbers are allowed.) For example, you could change a 5 into a 4, 3, 2, 1, or 0. 
Erase a zero and all the digits to the right of it.


The player who removes the last digit wins.


The game that begins with the string of numbers above could proceed like this: 



Now, given a initial string, try to determine can the first player win if the two players play optimally both. 
 

 

Input
The input consists of several test cases. For each case, there is a string in one line.

The length of string will be in the range of [1,6]. The string contains only digit characters.

Proceed to the end of file.
 

 

Output
Output Yes in a line if the first player can win the game, otherwise output No.
 

 

Sample Input
0 00 1 20
 

 

Sample Output
Yes Yes No No
 

 

Author
ZHENG, Jianqiang
 

 

Source
 
     学的东西学不好总会干扰自己,一看到这个就想sg函数,,但是由于每个状态的子状态太多了,一一枚举的话不太现实。注意到这个游戏就是一个单独的游戏,不可利用sg定理分成多个子游戏,所以我们只要知道这个状态是0 or 1就好了,不必计算出所有的sg值= =,还是自己思维太固定了。
   这样的话可以利用必败态推出所有的必胜态,0表示lose,1表示win即可。
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 bool sg[1000010];
 4 void dfs(int n,int l){
 5     if(l>6) return;
 6     n=n*10;
 7     for(int i=0;i<=9;++i){
 8         if(n+i>1000000) break;
 9         sg[n+i]=1;
10         dfs(n+i,l+1);
11     }
12 }
13 void init(){
14     sg[0]=1;
15     sg[1]=0;
16     for(int i=1;i<=1000000;++i){
17         if(!sg[i]){
18             int m=i,n=i,base=1;
19             while(n){
20                 int q=9-n%10;
21                 for(int j=1;j<=q&&m+j*base<=1000000;++j){
22                     sg[m+j*base]=1;
23                     //if(i==233)cout<<m+j*base<<endl;
24                 }
25                 n/=10;
26                 base*=10;
27             }
28             if(i<=99999){
29                 int n=i*10;
30                 sg[n]=1;
31                 int l=log10(n+0.5)+1;
32                 dfs(n,l);
33             }
34         }
35     }
36 }
37 int main(){
38     char s[10];
39     init();
40     while(scanf("%s",s)!=EOF){
41         if(s[0]=='0'){
42             puts("Yes");
43             continue;
44         }
45         int n=0,len=strlen(s);
46         for(int i=0;i<len;++i)
47             n=n*10+(s[i]-'0');
48         sg[n]?puts("Yes"):puts("No");
49     }
50     return 0;
51 }

 

转载于:https://www.cnblogs.com/zzqc/p/9349325.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值