Digital Deletions HDU - 1404
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的更多相关文章
- hdu 1404 找sg ***
HDU 1404 Digital Deletions 一串由0~9组成的数字,可以进行两个操作:1.把其中一个数变为比它小的数:2.把其中一个数字0及其右边的所以数字删除. 两人轮流进行操作,最后把 ...
- Hdu 1404 Digital Deletions
Problem地址:http://acm.hdu.edu.cn/showproblem.php?pid=1404 刚开始想采取找规律的方法解题,可以没有发现规律.无奈,只好采用求PN点的方法. 我们假 ...
- hdu 1404/zoj 2725 Digital Deletions 博弈论
暴力打表!! 代码如下: #include<iostream> #include<algorithm> #include<cstdio> #include<c ...
- HDU 1404 (博弈) Digital Deletions
首先如果第一个数字是0的话,那么先手必胜. 对于一个已知的先手必败状态,凡是能转移到先手必败的状态一定是必胜状态. 比如1是必败状态,那么2~9可以转移到1,所以是必胜状态. 10,10*,10**, ...
- HDU 1404 Digital Deletions (暴力博弈)
题意:给定一个数字串,最长是6,然后有两种操作. 第一种是,把该串中的一个数字换成一个比该数字小的数,比如 5 可以换成 0,1,2,3,4. e.g. 12345 --> 12341 第二 ...
- hdoj 1404 Digital Deletions(博弈论)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1404 一看就是博弈论的题目,但并没有什么思路,看了题解,才明白 就是求六位数的SG函数,暴力一遍,打表 ...
- 【Mark】博弈类题目小结(HDU,POJ,ZOJ)
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 首先当然要献上一些非常好的学习资料: 基础博弈的小 ...
- 博弈论BOSS
基础博弈的小结:http://blog.csdn.net/acm_cxlove/article/details/7854530 经典翻硬币游戏小结:http://blog.csdn.net/acm_c ...
- 【转】ACM博弈知识汇总
博弈知识汇总 转自:http://www.cnblogs.com/kuangbin/archive/2011/08/28/2156426.html 有一种很有意思的游戏,就是有物体若干堆,可以是火柴棍 ...
随机推荐
- vi中如何使用cscope来查找函数的定义
答:进入命令行模式输入:cs f g <function_name>
- [转] Java 基础
1. 面向对象和面向过程的区别 面向过程 面向对象 2. Java 语言有哪些特点 3. 关于 JVM JDK 和 JRE 最详细通俗的解答 JVM JDK 和 JRE 4. Oracle JDK 和 ...
- oracle 之 如何链接别人电脑的oracle
1.首先确保两台电脑是在同一个局域网内,可以通过cm命令窗口 ping 对方电脑的ID,若是没问题则表示可以连接 2.接下来通过配置来首先连接对方的电脑 其实在后面还有一个是否创建新的额服务名的操作, ...
- HihoCoder 1195 高斯消元·一(高斯消元)
题意 https://hihocoder.com/problemset/problem/1195 思路 高斯消元是解决高元方程的一种算法,复杂度 \(O(n^3)\) . 过程大致是: 构造一个未知数 ...
- Python实现机器学习算法:逻辑回归
import numpy as np import matplotlib.pyplot as plt from sklearn.datasets.samples_generator import ma ...
- java.lang.OutOfMemoryError:GC overhead limit exceeded
在调测程序时报java.lang.OutOfMemoryError:GC overhead limit exceeded 错误 错误原因:在用程序进行数据切割时报了该错误.由于在本地执行数据切割测试的 ...
- 【译】第19节---数据注解-NotMapped
原文:http://www.entityframeworktutorial.net/code-first/notmapped-dataannotations-attribute-in-code-fir ...
- 使用explain来分析SQL语句实现优化SQL语句
用法:explain sql 作用:用于分析sql语句 mysql> explain select * from quser_1 where loginemail = "quctest ...
- 在Idea创建Spring Boot + MyBatis的web项目
创建步骤如下 选择Spring initializr 2. 修改group 与 atifact id,点击next 3. dependencies里面选择Web->Web , SQL -> ...
- 转youhu科技的文章 勿怪 感激 感激
资源加载 资源加载是加载模块中最为耗时的部分,其CPU开销在Unity引擎中主要体现在Loading.UpdatePreloading和Loading.ReadObject两项中,相信经常查看Prof ...