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且都是素数 不用素数打表都能过,数据 ...
随机推荐
- 处理内容有&特殊字符thinkphp返回xml无法解析的问题<![CDATA[xxx]]>
处理内容有&特殊字符thinkphp返回xml无法解析的问题<![CDATA[xxx]]> // xml 转义特殊字符 如&'" <![CDATA[&quo ...
- Python入门之Python引用模块和查找模块路径
#这篇文章主要介绍了Python引用模块和Python查找模块路径的相关资料,需要的朋友可以参考下 模块间相互独立相互引用是任何一种编程语言的基础能力.对于“模块”这个词在各种编程语言中或许是不同的, ...
- 02:Django进阶篇
目录:Django其他篇 01:Django基础篇 02:Django进阶篇 03:Django数据库操作--->Model 04: Form 验证用户数据 & 生成html 05:Mo ...
- Linq join right join left join
代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syst ...
- <OFFER03>03_01_DuplicationInArray
#include<cstdio> bool duplicate(int numbers[], int length, int* duplication) { ) return false; ...
- [BZOJ1776][Usaco2010 Hol]cowpol 奶牛政坛
Description 农夫约翰的奶牛住在N (2 <= N <= 200,000)片不同的草地上,标号为1到N.恰好有N-1条单位长度的双向道路,用各种各样的方法连接这些草地.而且从每片 ...
- 论文笔记—Flattened convolution neural networks for feedforward acceleration
1. 论文思想 一维滤过器.将三维卷积分解成三个一维卷积.convolution across channels(lateral), vertical and horizontal direction ...
- Javascript库的产生和解读
javascript库的产生,增强了浏览器或javascript语言的某些机制的功能, 让业务开发人员,更专注业务逻辑,而不是机制逻辑. 比如, 0.兼容性 同样的功能函数,不同的浏览器所暴露的a ...
- python 元组切片
#create a tuple tuplex = (, , , , , , , , , ) #used tuple[start:stop] the start index is inclusive a ...
- vim/vi中移动光标键会变成A,B,C,D的解决办法
在某些情况下, vi/vim中的编辑会出现一些很不愉快的情况, 比如在vi/vim中输入方向键有时被转化为A B C D, 或者按个Enter键, 却被转为为其他字母, 恼人得很, 该怎么办呢? 方法 ...