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 思路:必败态可以转移到必胜态,sg搜一下。
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int MAX=;
int sg[MAX];
int getlength(int n){
if(n/) return ;
if(n/) return ;
if(n/) return ;
if(n/) return ;
if(n/) return ;
return ;
}
void extend(int n){
int len=getlength(n);
for(int i=len;i>;i--){
int m=n;
int x=;
for(int j=;j<i;j++) x*=;
int index=(n%(x*))/x;
for(int j=index;j<;j++){
m+=x;
sg[m]=;
}
}
if(len<){
int m=n;
int x=;
for(int i=len;i<;i++)
{
m*=;
for(int i=;i<x;i++)
sg[m+i]=;
x*=;
}
}
}
void fun(){
memset(sg,,sizeof(sg));
sg[]=;
for(int i=;i<MAX;i++)
if(!sg[i])
extend(i);
}
int main(){
char str[];
int n;
fun();
while(scanf("%s",&str)!=EOF)
{
if(str[]=='') //第一个数字是0,则前者必胜
{
printf("Yes\n");
continue;
}
int len=strlen(str);//第一个数字非0,再转化成整型数
n=;
for(int i=;i<len;i++)
{
n*=;
n+=str[i]-'';
}
if(sg[n]) printf("Yes\n");
else printf("No\n");
}
return ;
}

Digital Deletions HDU - 1404的更多相关文章

  1. hdu 1404 找sg ***

    HDU 1404  Digital Deletions 一串由0~9组成的数字,可以进行两个操作:1.把其中一个数变为比它小的数:2.把其中一个数字0及其右边的所以数字删除. 两人轮流进行操作,最后把 ...

  2. Hdu 1404 Digital Deletions

    Problem地址:http://acm.hdu.edu.cn/showproblem.php?pid=1404 刚开始想采取找规律的方法解题,可以没有发现规律.无奈,只好采用求PN点的方法. 我们假 ...

  3. hdu 1404/zoj 2725 Digital Deletions 博弈论

    暴力打表!! 代码如下: #include<iostream> #include<algorithm> #include<cstdio> #include<c ...

  4. HDU 1404 (博弈) Digital Deletions

    首先如果第一个数字是0的话,那么先手必胜. 对于一个已知的先手必败状态,凡是能转移到先手必败的状态一定是必胜状态. 比如1是必败状态,那么2~9可以转移到1,所以是必胜状态. 10,10*,10**, ...

  5. HDU 1404 Digital Deletions (暴力博弈)

    题意:给定一个数字串,最长是6,然后有两种操作. 第一种是,把该串中的一个数字换成一个比该数字小的数,比如 5 可以换成 0,1,2,3,4.   e.g. 12345 --> 12341 第二 ...

  6. hdoj 1404 Digital Deletions(博弈论)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1404 一看就是博弈论的题目,但并没有什么思路,看了题解,才明白 就是求六位数的SG函数,暴力一遍,打表 ...

  7. 【Mark】博弈类题目小结(HDU,POJ,ZOJ)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 首先当然要献上一些非常好的学习资料: 基础博弈的小 ...

  8. 博弈论BOSS

    基础博弈的小结:http://blog.csdn.net/acm_cxlove/article/details/7854530 经典翻硬币游戏小结:http://blog.csdn.net/acm_c ...

  9. 【转】ACM博弈知识汇总

    博弈知识汇总 转自:http://www.cnblogs.com/kuangbin/archive/2011/08/28/2156426.html 有一种很有意思的游戏,就是有物体若干堆,可以是火柴棍 ...

随机推荐

  1. 小C的数学问题 【单调栈】

    问题 J: 小C的数学问题 时间限制: 1 Sec  内存限制: 128 MB 提交: 565  解决: 141 [提交] [状态] [命题人:外部导入] 题目描述 小C是个云南中医学院的大一新生,在 ...

  2. 学习使用JUnit4进行单元测试

    借用http://blog.csdn.net/andycpp/article/details/1327147等文章上面的例子和教程进行学习总结,自己敲了一遍代码,发现里面有些东西,可能版本原因,已经稍 ...

  3. 传输SO10 (SO10 Transport)

    传输SO10 (SO10 Transport) 方法一.   手工添加到请求里面,格式为: R3TR TEXT text object, name, ID, language   方法二.使用程序:R ...

  4. 【Java】【图形】

    /* 栗子 了解swing */import javax.swing.*;public class test_swing extends JFrame { //继承JFrame顶层容器类(可以添加其他 ...

  5. linux 换源

    Ubuntu换源 ubuntu 的默认源是美国的,所以下载起来特别慢.更换国内源:用vi和gedit 打开 /etc/apt/sources.list 将其中的us.archive 全部替换为 cn. ...

  6. Redis 图形化监控方案 RedisLive

    一款开源的 Redis 图形化监控工具,界面如图所示 安装 首先安装python2 一般情况下系统自带 然后安装pip2 https://www.cnblogs.com/sea-stream/p/10 ...

  7. python redis 操作

    1.String 操作 redis中的String在在内存中按照一个name对应一个value来存储 set() #在Redis中设置值,默认不存在则创建,存在则修改 r.set('name', 'z ...

  8. PHP 的命令行模式

    php CLI SAPI 内置Web Server 从版本 4.3.0 开始,PHP 提供了一种新类型的 CLI SAPI(Server Application Programming Interfa ...

  9. VC.时间(网页内容收集)

    1.VC++获得当前系统时间的几种方案_记忆53秒_新浪博客.html(http://blog.sina.com.cn/s/blog_676271a60101i0hb.html) 1.1.内容保存: ...

  10. [HTTP]_[C/C++]_[解析URL的转义字符百分比字符串]

    场景: 1.有时候获取一个超链接时,或者一个图片src时,里面的地址带有%XX,这样如果当成文件路径处理会不识别.所以要把转义字符解码. 2.它其实就是ASCII码的十六进制表示. 以下是stacko ...