描述

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

输入

* Line 1: A single integer: G

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

输出

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

样例输入

2
9
10

样例输出

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.

题意

A和B在玩游戏,给一个数a,轮到A,可以把数变成a-最大的数,a-最小的非零数,B同理,谁把值变成0谁赢

题解

观察一下可以发现,只要知道a-最大的数的sg值和a-最小的非零数的sg值,再异或1就是答案

因为先手只可以选最大或最小,后面不管怎么拿都是定死了

代码

 #include<bits/stdc++.h>
using namespace std; int sg[],n,a,t,mx,mi;
void m(int x)
{
mx=-,mi=;
do{
t=x%;
if(t)mx=max(mx,t);
if(t)mi=min(mi,t);
x/=;
}while(x);
}
int main()
{
sg[]=;
for(int i=;i<=;i++)m(i),sg[i]=(sg[i-mx]^)|(sg[i-mi]^);
scanf("%d",&n);
while(n--)
{
scanf("%d",&a);
printf("%s\n",sg[a]?"YES":"NO");
}
return ;
}

TZOJ 2703 Cow Digit Game(sg博弈)的更多相关文章

  1. TOJ 2703: Cow Digit Game

    2703: Cow Digit Game Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByte Total Submit ...

  2. BZOJ3404: [Usaco2009 Open]Cow Digit Game又见数字游戏

    3404: [Usaco2009 Open]Cow Digit Game又见数字游戏 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 47  Solved ...

  3. 3404: [Usaco2009 Open]Cow Digit Game又见数字游戏

    3404: [Usaco2009 Open]Cow Digit Game又见数字游戏 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 72  Solved ...

  4. 洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game

    洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game 题目描述 Bessie is playing a number game against Farmer John, ...

  5. UVA12293 Box Game —— SG博弈

    题目链接:https://vjudge.net/problem/UVA-12293 题意: 两人玩游戏,有两个盒子,开始时第一个盒子装了n个球, 第二个盒子装了一个球.每次操作都将刷量少的盒子的球倒掉 ...

  6. UVA1482 Playing With Stones —— SG博弈

    题目链接:https://vjudge.net/problem/UVA-1482 题意: 有n堆石子, 每堆石子有ai(ai<=1e18).两个人轮流取石子,要求每次只能从一堆石子中抽取不多于一 ...

  7. HDU 1848(sg博弈) Fibonacci again and again

    Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  8. [USACO09OPEN]牛的数字游戏Cow Digit Game 博弈

    题目描述 Bessie is playing a number game against Farmer John, and she wants you to help her achieve vict ...

  9. 【博弈论】【SG函数】bzoj3404 [Usaco2009 Open]Cow Digit Game又见数字游戏

    #include<cstring> #include<cstdio> #include<algorithm> #include<set> using n ...

随机推荐

  1. android全屏/沉浸式状态栏下,各种键盘挡住输入框解决办法

    https://blog.csdn.net/smileiam/article/details/69055963

  2. LeetCode 791. Custom Sort String

    题目链接:https://leetcode.com/problems/custom-sort-string/description/ S and T are strings composed of l ...

  3. Redis 认识与安装

    1. redis是一种Nosql数据库,使用key-value存储数据,因为基于内存存储,所以可以用来做缓存(mysql等数据库是基于表基于数据库的) 2. 和memcathed的区别 redis会生 ...

  4. gunicorn开启、关闭和重启

    1.gunicorn开启 在项目的根目录下,输入下方的代码. gunicorn --bind unix:/tmp/域名.socket projectname.wsgi:application 2.查询 ...

  5. 215.Spring Boot+Spring Security:初体验

    [视频&交流平台] SpringBoot视频:http://t.cn/R3QepWG Spring Cloud视频:http://t.cn/R3QeRZc SpringBoot Shiro视频 ...

  6. 关于python的多行注释,启动新浏览器,循环语句乘法口诀

    1,提问:如何将python写的多行代码改写成注释,进行写下一段代码?这样可以在多个脚本中写东西? 回答:百度了一下,还真有 选中所要注释的代码  CTRL + / 然后所选的代码前面都会出现#,编程 ...

  7. java中对list进行分页显示数据到页面

    http://blog.csdn.net/Tang_Mr/article/details/76212184#10006-weixin-1-52626-6b3bffd01fdde4900130bc5a2 ...

  8. python算法之冒泡排序和选择排序

    一.冒泡排序(Bubble sort) Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorith ...

  9. leetcode1033

    class Solution: def numMovesStones(self, a: int, b: int, c: int) -> 'List[int]': l = list() l.app ...

  10. --- Android 设置为A2DP 接收器

    http://www.it1352.com/88728.html external/bluetooth/bluedroid/include/bt_target.h: * Enable bluetoot ...