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. pyDay3

    内容来自廖雪峰的官方网站 1.关键字参数 def person(**kw): print(kw) >>> person(name=') {'} 关键字参数有什么用?它可以扩展函数的功 ...

  2. mysql 触发器 trigger用法 three (稍微复杂的)

    MySQL包含对触发器的支持.触发器是一种与表操作有关的数据库对象,当触发器所在表上出现指定事件时,将调用该对象,即表的操作事件触发表上的触发器的执行. 创建触发器 在MySQL中,创建触发器语法如下 ...

  3. Jquery 数组与字符串之间的转换

    var auth_list = []; $("input[name='auth_list']:checkbox").each(function () { if ($(this).a ...

  4. C++ tinyXML的使用和字符编码转换

    转载:http://jetyi.blog.51cto.com/1460128/761708/ 关于tinyxml使用的文档有很多(这篇文章就写的很好),这里仅提一下字符编码的转换问题,如果你不熟悉字符 ...

  5. C++11 正则表达式——实例系统(转载)

    一.用正则表达式判断邮箱格式是否正确 1 #include <regex> #include <iostream> #include <string> bool i ...

  6. MFC使用MsComm做串口通信

    一.注册MSCOMM 1.下载控件MSCOMM32.OCX(32位),mswnisck.ocx(64位) 2.把这个ocx文件放在c盘WIndows的system32里,打开cmd执行:regsvr3 ...

  7. 高通RFC适配RFFE-添加MIPI设备【转】

    本文转载自:https://blog.csdn.net/u011212816/article/details/80828625 RF driver主要设计到的器件 1.Transceiver 2.RF ...

  8. git如何获取用户名和邮箱

    答: git config user.name  (获取用户名)   git config user.email (获取邮箱)

  9. bootstrap的 附加导航Affix导航 (侧边窄条式 滚动监控式导航) 附加导航使用3.

    affix: 意思是粘附, 附着, 沾上. 因此, 附加导航就是 bootstrap的 Affix.js组件. bootstrap的 附加导航, 不是说导航分成主导航, 或者什么 副导航的 而是指, ...

  10. 【TCP/IP详解 卷一:协议】第一章概论 学习笔记

    第一章 概述 游览了一下,本章主要是简介OSI模型的低层(1-4层).介绍了TCP/IP协议族的相关知识. TCP/IP的分层 Application <--> TCP / UDP < ...