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. 《OFFER14》14_CuttingRope

      // 面试题14:剪绳子 // 题目:给你一根长度为n绳子,请把绳子剪成m段(m.n都是整数,n>1并且m≥1). // 每段的绳子的长度记为k[0].k[1].…….k[m].k[0]*k ...

  2. 分布式事务框架&解决方案参考

    两种开源解决方案框架介绍: https://blog.csdn.net/zyndev/article/details/79604395#_97 LCN: https://www.jianshu.com ...

  3. (转)开源项目miaosha(下)

    石墨文档:https://shimo.im/docs/2XlwliBQAYsKCHbq/ (二期)20.开源秒杀项目miaosha解读(下) [课程20]jmeter.xmind81.5KB [课程2 ...

  4. 百度搜索引擎取真实地址-python代码

    代码 def parseBaidu(keyword, pagenum): keywordsBaseURL = 'https://www.baidu.com/s?wd=' + str(quote(key ...

  5. 【ASP.NET】The CodeDom provider type “Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider” could not be located

    一般是asp.net的项目在启动的时候会报这个错误. 页面显示成: 我推测的原因是由于project的build的输出属性改了, 非bin目录下, 导致这个问题. 解决这个问题的方案有两个: 1. 改 ...

  6. 在C#中理解和实现策略模式的绝对入门教程

    介绍 本文的目的是理解战略模式的基础知识,并试图了解何时可以使用,并有一个基本的实现,以便更好地理解.在现实世界的应用中,这是无法实施战略模式的,所采用的例子也远没有实际可行.这篇文章的想法只是为了说 ...

  7. HTML-CSS-JS-JQ常用知识点总结

    html:展示文件 标签:<html><head><title></title><meta><link><style> ...

  8. mapgis IGServer账号

    2064803644@qq.com 1576391020@qq.com 密码一样

  9. dplyr-高效的数据变换与整理工具--转载

    1.背景简介 在数据分析工作中,经常需要对原始的数据集进行清洗.整理以及变换.常用的数据整理与变换工作主要包括:特定分析变量的选取.满足条件的数据记录的筛选.按某一个或几个变量排序.对原始变量进行加工 ...

  10. mail命令

    mail命令是命令行的电子邮件发送和接收工具.操作的界面不像elm或pine那么容易使用,但功能非常完整. 语法 mail(选项)(参数) 选项 -b<地址>:指定密件副本的收信人地址: ...