# USACO 2009 Open Silver 3.Cow Digit Game简单博弈论

149人阅读 评论(0)

Description

Bessie is playing a number game against Farmer John, and she wants you to help her achieve victory.

Game i starts with an integer N_i (1 <= N_i <= 1,000,000). Bessie goes first, and then the two players alternate turns. On each turn, a player can subtract either the larges digit or the smallest non-zero digit from the current number to obtain a new number. For example, from 3014 we may subtract either 1 or 4 to obtain either 3013 or 3010, respectively. The game continues until the number becomes 0, at which point the last player to have taken a turn is the winner.

Bessie and FJ play G (1 <= G <= 100) games. Determine, for each game, whether Bessie or FJ will win, assuming that both play perfectly (that is, on each turn, if the current player has a move that will guarantee his or her win, he or she will take it).

Consider a sample game where N_i = 13. Bessie goes first and takes 3, leaving 10. FJ is forced to take 1, leaving 9. Bessie takes the remainder and wins the game.

Input
* Line 1: A single integer: G

* Lines 2..G+1: Line i+1 contains the single integer: N_i

Output
* Lines 1..G: Line i contains "YES" if Bessie can win game i, and "NO" otherwise.

Sample Input
2
9
10
Sample Output
YES
NO

OUTPUT DETAILS:

For the first game, Bessie simply takes the number 9 and wins. For the second game, Bessie must take 1 (since she cannot take 0), and then FJ can win by taking 9.

#include<stdio.h>
int sg[1000010],num[10],len;
int maxi,mini;
int main()
{
sg[0]=0;
int i,t,n;
len=0;
for(i=1;i<=1000000;i++)
{
t=i;
maxi=0;
mini=10;
while(t)
{
if(t%10>maxi)
maxi=t%10;
if(t%10>0&&t%10<mini)
mini=t%10;
t/=10;
}
sg[i]=(sg[i-maxi]&sg[i-mini])^1;
}
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&t);
if(sg[t])
printf("YES\n");
else
printf("NO\n");
}
return 0;
}


0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：530次
• 积分：64
• 等级：
• 排名：千里之外
• 原创：6篇
• 转载：0篇
• 译文：0篇
• 评论：1条
文章分类
文章存档
最新评论