hdu-1404-博弈+打表
Digital Deletions
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3312 Accepted Submission(s): 1194
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.
The length of string will be in the range of [1,6]. The string contains only digit characters.
Proceed to the end of file.
00
1
20
Yes
No
No
#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-博弈+打表的更多相关文章
- HDU 1404 (博弈) Digital Deletions
首先如果第一个数字是0的话,那么先手必胜. 对于一个已知的先手必败状态,凡是能转移到先手必败的状态一定是必胜状态. 比如1是必败状态,那么2~9可以转移到1,所以是必胜状态. 10,10*,10**, ...
- HDU 3032 multi-sg 打表找规律
普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2 ...
- S-Nim HDU 1536 博弈 sg函数
S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...
- hdu 1404 找sg ***
HDU 1404 Digital Deletions 一串由0~9组成的数字,可以进行两个操作:1.把其中一个数变为比它小的数:2.把其中一个数字0及其右边的所以数字删除. 两人轮流进行操作,最后把 ...
- hdu 1496 Equations hash表
hdu 1496 Equations hash表 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1496 思路: hash表,将原来\(n^{4}\)降 ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- HDU 5795 A Simple Nim (博弈 打表找规律)
A Simple Nim 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5795 Description Two players take turns ...
- HDU 5795 A Simple Nim ——(Nim博弈 + 打表)
题意:在nim游戏的规则上再增加了一条,即可以将任意一堆分为三堆都不为0的子堆也视为一次操作. 分析:打表找sg值的规律即可. 感想:又学会了一种新的方法,以后看到sg值找不出规律的,就打表即可~ 打 ...
- HDU 1404 Digital Deletions (暴力博弈)
题意:给定一个数字串,最长是6,然后有两种操作. 第一种是,把该串中的一个数字换成一个比该数字小的数,比如 5 可以换成 0,1,2,3,4. e.g. 12345 --> 12341 第二 ...
- hdu 5104 素数打表水题
http://acm.hdu.edu.cn/showproblem.php?pid=5104 找元组数量,满足p1<=p2<=p3且p1+p2+p3=n且都是素数 不用素数打表都能过,数据 ...
随机推荐
- Qt学习之路(45): 自定义model之一
前面我们说了Qt提供的几个预定义model.但是,面对变化万千的需求,那几个model是远远不能满足我们的需要的.另外,对于Qt这种框架来说,model的选择首先要能满足绝大多数功能的需要,这就是说, ...
- ACM题目————STL练习之求次数
题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=1112 描述 题意很简单,给一个数n 以及一个字符串str,区间[i,i+n-1] 为一个 ...
- P1516/bzoj1477 青蛙的约会
青蛙的约会 exgcd 根据题意列出方程: 设所用时间为T,相差R圈时相遇 (x+T*m)-(y+T*n)=R*l 移项转换,得 T*(n-m)-R*l=x-y 设a=n-m,b=l,c=x-y,x_ ...
- mysql免安装版本(用批处理安装和启动)
参考文章: http://www.cnblogs.com/niuniutry/p/3555778.html http://wenku.baidu.com/link?url=WI9Cyl5AMHOlps ...
- 20145105 《Java程序设计》第7周学习总结
20145105 <Java程序设计>第7周学习总结 教材学习内容总结 第十三章 时间与日期 一.认识时间与日期 (一)时间的度量 格林威治标准时间 世界时 国际原子时 世界协调时 Uni ...
- 20145118《Java程序设计》 第7周学习总结
20145118<Java程序设计> 第7周学习总结 教材学习内容总结 本周学习内容为第十三章,以下为教材内容重点总结: 1.格林威治标准时间简称GMT时间. 2.java.util.Da ...
- Android项目开发三
微博客户端开发 本周学习计划 运用OAuth相关知识,解决上周出现的微博验证问题. 看懂微博客户端登录.用户主页等功能代码. 将程序中存在的问题解决. 实际完成情况 本周继续研究了OAuth相关知识, ...
- poj Meteor Shower - 搜索
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16313 Accepted: 4291 Description Bess ...
- linux下设置软件使用socks5代理
1.为wget使用代理,可以直接修改/etc/wgetrc,也可以在主文件夹下新建.wgetrc,并编辑相应内容,本文采用后者. 直接往~/.wgetrc(自行创建此文件)添加如下内容: https_ ...
- Dubbo学习参考
参考博客: 小宝鸽:https://blog.csdn.net/u013142781/article/details/50387583 https://blog.csdn.net/u013142781 ...