Digital Deletions
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1413 Accepted Submission(s): 509
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.
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.
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用str[n]来表示当序列为n时,第一个人是否一定获胜。若 序列为第一个人输,那么序列的每一位可以取大于该位小于9的数,即加多一步,所以新的序列为first赢。AC代码:#include <iostream> #include <cstring> #include <cstdio> #define MAXN 1000000 using namespace std; int str[MAXN]; int getlen(int n) { if(n/100000) return 6; if(n/10000) return 5; if(n/1000) return 4; if(n/100) return 3; if(n/10) return 2; return 1; } void f(int n) { int len=getlen(n); for(int i=len;i>=1;i--) //如果序列为first输,那么序列的每一位取大于该位的数,新的序列为first赢 { int m=n; int base=1; for(int j=1;j<i;j++) base*=10; int tmp=(m%(base*10))/base; for(int j=tmp;j<9;j++) { m+=base; str[m]=1; } } if(len!=6) //如果序列不满6位,则可以在后一位上加0 { int m=n; int base=1; for(int i=len;i<6;i++) { m*=10; for(int j=0;j<base;j++) str[m+j]=1; base*=10; } } } void fun() { memset(str,0,sizeof(str)); str[0]=1; for(int i=1;i<MAXN;i++) if(!str[i]) f(i); } int main() { char s[10]; int n; fun(); while(scanf("%s",s)!=EOF) { if(s[0]=='0') { printf("Yes\n"); continue; } else { int len=strlen(s); n=0; for(int i=0;i<len;i++) { n*=10; n+=s[i]-'0'; } if(str[n]) printf("Yes\n"); else printf("No\n"); } } return 0; }