博弈——Digital Deletions

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. 
InputThe 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. 
OutputOutput 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


题意:给一串数字,有两个玩家,每回合可以将某个数字改成比它小的数(所有数字包括改之后都为非负整数),或者将某个0和0的右边都消去。能执行最后一次移动的玩家为赢,求最先移动的人是否能赢。

思路:

因为范围较小可以先将每个数字的胜负态sg置0表示为输,然后sg[0]=1,表示为0的时候会赢,然后往后找必败态,找到后进行筛选将必败态能转移到的数值置1表示必胜。

例如:

1为必败态而1能转移到2~9和10~109999,所以可以将这些数值置1,然后一直找下去,这样就可以事先打好表。


#include 
#include 
#include 
#include 
using namespace std;
const int maxn=1000000;
int sg[maxn];
int a[10];
int qu_len(int x)     //求数值的长度
{
    int cnt=1;
    while(x/10)
    {
        cnt++;
        x/=10;
    }
    return cnt;
}
void work(int x)    //对x这种必败态进行转移
{
    int len=qu_len(x);
    for(int i=1; i<=len; i++)
    {
        int m=x;
        int pos=1;
        for(int j=1; j




你可能感兴趣的:(博弈)