Hdu1404 Digital Deletions(暴力SG博弈)

Digital Deletions

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


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
 

题意:给一个长度不超过6字符的数字字符串。两种操作二选一:

1、把任意一位变成比他本身小的数字。比如205,可以把5变成0,1,2,3,4,成了200,201.so on。

2、把任意一个0后及他本身去掉。比如205,去掉2和他后面的数字变成了2。

问最后去掉数字的算赢。问先手有木有必胜策略。

题解:可以通过SG函数的性质。暴力吧1-1e6每个数字的状态求出来。能一步到达必败状态的都为必胜点。sg[1]明显是必败点,每次从必败点去找。怎么找?

1、可以将每位上的数字+1,直到等于9.

2、如果位数小于6,可在末尾+0.再加上若干数。最后只要知道sg值是0或者1就OK了。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <vector>
using namespace std;
#define LL __int64
int sg[1000010];
int getl(int x)
{
	for (int i=6;i>0;i--)
	{
		int k=pow(10,(i-1));
		if (x / k) return i;
	}
}
void findsg(int x)
{
	int i,j,l=getl(x);
	for (i=1;i<=l;i++)
	{
		int k=pow(10,(i-1));
		int q=x/k%10;
		int y=x;
		for (j=q;j<9;j++)
		{
			y+=k;
			sg[y]=1;
		}
	}
	int y=x,k=1;
	while (l<6)
	{
		y=y*10;
		for (i=0;i<k;i++)
			sg[y+i]=1;
		k=k*10;
		l++;
	}
}
char s[10];
int main()
{
	memset(sg,0,sizeof(sg));
	sg[0]=1;
	for (int i=1;i<1000000;i++)
		if (!sg[i]) findsg(i);
	while (gets(s))
	{
		if (s[0]=='0') puts("Yes");
		else
		{
			int k=atoi(s);
			//cout<<sg[k]<<endl;
			if (sg[k]) puts("Yes");
			else puts("No");
		}
	}
	return 0;
}




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值