hdu 1404

Digital Deletions

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

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
 

 

 1 /*
 2 分析:
 3 1是必败点那么所有被操作成1的数都是必胜点,
 4 以此类推由必败点按找游戏的规则反方向推出
 5 所有的必胜点。
 6 */
 7 #include
 8 #include<string>
 9 #include
10 #include
11 using namespace std;
12 bool sg[1000000];
13 
14 int get_length(int n)//得到整数n的位数 
15 {
16     if(n/100000) return 6;
17     if(n/10000) return 5;
18     if(n/1000)  return 4;
19     if(n/100)   return 3;
20     if(n/10)  return 2;
21     return 1;
22 }    
23   
24 void Deal(int n)
25 {
26     int m,i,j,base,len,t;
27     len=get_length(n);
28     for(i=1;i<=len;i++)//对每一位上加上一个数
29     {
30         m=n;
31         base=pow(10,i-1);
32         t=(m%(base*10))/base;
33         for(j=t;j<9;j++)
34         {
35             m+=base;
36             sg[m]=true;
37         }
38     }
39     m=n;
40     base=1;
41     for(i=len;i<6;i++)//后面加0开头的数
42     {
43         m*=10;
44         for(j=0;j<base;j++)
45             sg[m+j]=true;
46         base*=10;
47     }
48 }
49 void Init()
50 {
51     memset(sg,false,sizeof(sg));
52     int i;
53     for(i=1;i<1000000;i++)//由必败点找出所有的必胜点
54         if(!sg[i])
55             Deal(i);
56 }
57 int main()
58 {
59     string s;
60     int i,sum;
61     Init();
62     while(cin>>s)
63     {
64         if(s[0]=='0')//0开头的都是必胜的
65         {
66             printf("Yes\n");
67             continue;
68         }
69         sum=0;
70         for(i=0;i//字符串转变成整型
71             sum=sum*10+s[i]-'0';
72         if(sg[sum])
73             printf("Yes\n");
74         else 
75             printf("No\n");
76     }
77     return 0;
78 }

 

 

 

 

转载于:https://www.cnblogs.com/xiong-/archive/2013/05/21/3089988.html

你可能感兴趣的:(hdu 1404)