Digital Deletions
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3312 Accepted Submission(s): 1194
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.
The length of string will be in the range of [1,6]. The string contains only digit characters.
Proceed to the end of file.
00
1
20
Yes
No
No
#include<bits/stdc++.h>
using namespace std;
bool sg[];
void dfs(int n,int l){
if(l>) return;
n=n*;
for(int i=;i<=;++i){
if(n+i>) break;
sg[n+i]=;
dfs(n+i,l+);
}
}
void init(){
sg[]=;
sg[]=;
for(int i=;i<=;++i){
if(!sg[i]){
int m=i,n=i,base=;
while(n){
int q=-n%;
for(int j=;j<=q&&m+j*base<=;++j){
sg[m+j*base]=;
//if(i==233)cout<<m+j*base<<endl;
}
n/=;
base*=;
}
if(i<=){
int n=i*;
sg[n]=;
int l=log10(n+0.5)+;
dfs(n,l);
}
}
}
}
int main(){
char s[];
init();
while(scanf("%s",s)!=EOF){
if(s[]==''){
puts("Yes");
continue;
}
int n=,len=strlen(s);
for(int i=;i<len;++i)
n=n*+(s[i]-'');
sg[n]?puts("Yes"):puts("No");
}
return ;
}