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 有一种很有意思的游戏,就是有物体若干堆,可以是火柴棍 ...
随机推荐
- 【配置】log4j.properties 详解与配置步骤
一.Log4j基本使用方法 Log4j由三个重要的组件构成:[日志信息的优先级],[日志信息的输出目的地],[日志信息的输出格式]. 日志信息的优先级从高到低有ERROR.WARN. INFO.DEB ...
- R read.tabe line 5 did not have 2 elements
R read.tabe line 5 did not have 2 elements Reason: there are special characters such as # in file o ...
- 未能加载文件或程序集“System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKe
https://bbs.csdn.net/topics/392046946 电脑没安装mvc4,应该是,解决这个问题一上午了今天,然后装完了后就好了! https://www.microsoft.co ...
- Learning to Compare Image Patches via Convolutional Neural Networks --- Reading Summary
Learning to Compare Image Patches via Convolutional Neural Networks --- Reading Summary 2017.03.08 ...
- 改变onclick的作用域
- Shiro学习笔记六(自定义Reaml-使用数据库设置 user roles permissions)
1.工程目录 pom文件还和以前设置的一样就是添加了一个数据库驱动, <dependencies> <dependency> <groupId>junit</ ...
- redis事务之watch
三.redis事务之watch 首先要了解redis事务中watch的作用,watch命令可以监控一个或多个键,一旦其中有一个键被修改(或删除),之后的事务就不会执行.监控一直持续到exec命令(事务 ...
- 通过sql语句修改表的结构
1.修改表的列名 oracle: ALTER TABLE 表名 RENAME COLUMN 列名 TO 新列名sqlserver:exec sp_rename '[表名].[列名]','[表名].[新 ...
- gulp常用方法
var gulp = require('gulp'); var concat = require('gulp-concat'); //使用gulp-concat合并文件,减少网络请求(静态资源数量): ...
- Python.错误解决:scrapy 没有crawl 命令
确保2点: 1.把爬虫.py复制到spiders文件夹里 如执行scrapy crawl demo ,spiders里面就要有demo.py文件 2.在项目文件夹内执行命令 在scrapy.cfg所在 ...