Digital Deletions

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3312    Accepted Submission(s): 1194

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.

 
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.

 
Output
Output 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
 
Author
ZHENG, Jianqiang
 
Source
 
    学的东西学不好总会干扰自己,一看到这个就想sg函数,,但是由于每个状态的子状态太多了,一一枚举的话不太现实。注意到这个游戏就是一个单独的游戏,不可利用sg定理分成多个子游戏,所以我们只要知道这个状态是0 or 1就好了,不必计算出所有的sg值= =,还是自己思维太固定了。
   这样的话可以利用必败态推出所有的必胜态,0表示lose,1表示win即可。
 #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 ;
}

hdu-1404-博弈+打表的更多相关文章

  1. HDU 1404 (博弈) Digital Deletions

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

  2. HDU 3032 multi-sg 打表找规律

    普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2 ...

  3. S-Nim HDU 1536 博弈 sg函数

    S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...

  4. hdu 1404 找sg ***

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

  5. hdu 1496 Equations hash表

    hdu 1496 Equations hash表 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1496 思路: hash表,将原来\(n^{4}\)降 ...

  6. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  7. HDU 5795 A Simple Nim (博弈 打表找规律)

    A Simple Nim 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5795 Description Two players take turns ...

  8. HDU 5795 A Simple Nim ——(Nim博弈 + 打表)

    题意:在nim游戏的规则上再增加了一条,即可以将任意一堆分为三堆都不为0的子堆也视为一次操作. 分析:打表找sg值的规律即可. 感想:又学会了一种新的方法,以后看到sg值找不出规律的,就打表即可~ 打 ...

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

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

  10. hdu 5104 素数打表水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5104 找元组数量,满足p1<=p2<=p3且p1+p2+p3=n且都是素数 不用素数打表都能过,数据 ...

随机推荐

  1. MySQL笔记(六)游标练习

    23.3.1 Trigger Syntax and Examples 意义不明的几道练习,留着备用. 感觉不好写,而且难以调试..不知道以后会不会有实际的应用场景. 环境:MySQL 笔记(三)由 t ...

  2. CentOS 7 安装OpenCV

    CentOS 7 安装OpenCV步骤如下: 1.在CentOS 7命令行中直接在线安装: yum  install  numpy  opencv* 2.安装完成后进行全盘搜索:find  /  -n ...

  3. Python Web学习笔记之递归和迭代的区别

    电影故事例证:迭代——<明日边缘>递归——<盗梦空间> 迭代是更新变量的旧值.递归是在函数内部调用自身. 迭代是将输出做为输入,再次进行处理.比如将摄像头对着显示器:比如镜子对 ...

  4. Antlr4 SQL Query 解析实例

    grammar MysqlQuery; @header{package com.antlr.mysql.query;} AS : A S; SELECT : S E L E C T; FROM : F ...

  5. 算法之路 level 01 problem set

    2992.357000 1000 A+B Problem1214.840000 1002 487-32791070.603000 1004 Financial Management880.192000 ...

  6. 20145106java实验四

    实验名称:Java网络编程 实验内容: 1.掌握Socket程序的编写: 2.掌握密码技术的使用: 3.设计安全传输系统. 结对小伙伴 20145109竺文君 博客地址: 在本次实验中,是以我作为服务 ...

  7. [AtCoder ARC061F]Card Game for Three 组合数好题

    题目链接 总结:组合数 这$F$题好难啊...只会部分分做法,下面两个方法都是部分分做法.满分做法我去看看...会的话就补一下 部分分做法 方法1: 首先$A$能赢的条件很明显,假设在所有的牌里面取出 ...

  8. hibernate与mybatis的区别和应用场景

    mybatis 与 hibernate 的区别和应用场景(转) 1    Hibernate : 标准的ORM(对象关系映射) 框架: 不要用写sql, sql 自动语句生成: 使用Hibernate ...

  9. vs2010中自动给函数或者类加上注释宏模板

    Sub AddFunComment() Dim DocSel As EnvDTE.TextSelection DocSel = DTE.ActiveDocument.Selection DocSel. ...

  10. Pyinstaller 中 pandas出错问题的解决(详细)

    环境配置 pip install pyinstaller pyinstaller中的参数 -F 表示生成单个可执行文件 -c 显示命令行窗口,一般一开始的时候使用,如果没有错误,那就使用-w命令 -w ...