Digital Deletions+博弈
来源:互联网 发布:java web项目源码 编辑:程序博客网 时间:2024/05/17 15:17
Digital Deletions
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1426 Accepted Submission(s): 511
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
000120
Sample Output
YesYesNoNo/*HDU 1404*/#include<stdio.h>#include<math.h>#include<iostream>#include<string.h>using namespace std;const int MAXN=1000000;int sg[MAXN];int get_length(int n)//得到整数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 _extend(int n)//sg[n]=0;表示n为后者必胜 //那么所以可以一步变成n的都是前者必胜 { int len=get_length(n); int i; for(i=len;i>=1;i--)//每一个位上加上一个数 { int m=n; int base=1; for(int j=1;j<i;j++) base*=10; int tmp=(m%(base*10))/base; for(j=tmp;j<9;j++) { m+=base; sg[m]=1;//m为前者必胜点 } } if(len!=6)//长度小于6,则可以在后面加0开头的 { int m=n; int base=1; for(int i=len;i<6;i++) { m*=10; for(int b=0;b<base;b++) sg[m+b]=1; base*=10; } } cout<<endl;return ;} void fun(){ memset(sg,0,sizeof(sg)); sg[0]=1; for(int i=1;i<MAXN;i++) { if(!sg[i]) _extend(i); } } int main(){ char str[8]; int n; fun(); while(scanf("%s",&str)!=EOF) { if(str[0]=='0') //第一个数字是0,则前者必胜 { printf("Yes\n"); continue; } int len=strlen(str);//第一个数字非0,再转化成整型数 n=0; for(int i=0;i<len;i++) { n*=10; n+=str[i]-'0'; } if(sg[n]) printf("Yes\n"); else printf("No\n"); } return 0;}
- Digital Deletions+博弈
- Digital Deletions - HDU 1404 博弈
- 博弈——Digital Deletions
- Hdu1404 Digital Deletions(暴力SG博弈)
- HDU 1404 Digital Deletions [SG]【博弈】
- hdu1404 Digital Deletions------SG
- hdu 1404 Digital Deletions
- hdu 1404 Digital Deletions
- Hdu 1404 Digital Deletions
- hdu1404 Digital Deletions
- HDU 1404 Digital Deletions
- Hdu1404 Digital Deletions
- hdu1404 Digital Deletions (状压+dfs)
- hdu1404 Digital Deletions SG打表
- SG函数 hdu 1404 Digital Deletions
- sg函数 hdu 1404 Digital Deletions
- hdu 1404 Digital Deletions (SG函数)
- 博弈
- Pointers on C 读书笔记1 基本概念
- HDU 2196 树形dp
- C语言关键字const再理解
- mysql中导入txt文件数据的操作指令
- [USACO 3.1.6]邮票【同上:还是完全背包】CSUST 1084
- Digital Deletions+博弈
- 大话设计模式 享元模式
- cmd命令行进入相关目录
- HDU-1028Ignatius and the Princess III(母函数)
- 大三下学期,
- CTreeCtrl 自绘
- HDU1532--Drainage Ditches
- 设计一个类,该类不能被继承,且只能实例化3次
- 今天的收获 2013.5.3