描述

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. Immutable 学习

    1.什么是Immutable Data? Immutable Data 就是一旦创建,就不能再被更改的数据.对 Immutable 对象的任何修改或添加删除操作都会返回一个新的 Immutable 对 ...

  2. Vue 路由的模块化

    其实就是对路由配置和实例化的过程进行js封装,挂载路由的时候依然在main.js中: 步骤: 1.在src文件夹下新建一个router文件夹,在router文件夹下新建文件router.js; 2.引 ...

  3. js实现输入某串数字,构建完全二叉树,并判断是否为二叉搜索树

    思路:若为二叉搜索树,则中序遍历为递增的 let arr = [15,8,16,6,10];let pindex = [];function Node(){ this.root = null; thi ...

  4. 通过JS 给这个input加一个事件 获得焦点,回车事件绑定

    通过JS 给这个input加一个事件 就是获得焦点就行了 window.onload = function(){ var oInput = document.getElementById(" ...

  5. Problem B: 故障电灯(light)

    考虑对电灯进行差分:若第i个电灯和第i + 1个电灯状态不同,则在第i个位置上放一个球 这样我们就放置了不超过2n个球,且必然是偶数个 于是问题转化为:有m个球,每一步可以把一个球平移奇质数个位置,两 ...

  6. 类名:IExternalCommandAvailability+IExternalCommand实现对某些控件的自定义使用

    起初对于这些名词不懂,后经查阅了解如下,希望对学习者能有所帮助.在Revil里大部分命令在没有打开文档的时候是禁用的,有的在没有打开文档也是可以使用的.而又一些在平面视图是禁用的如标高,有的在3D视图 ...

  7. C# 使用NPOI 操作Excel

    首先 Nuget 引入NPOI 1.读取Excel /// <summary> /// 读取Excel数据 /// </summary> public static void ...

  8. 团队项目需求分析——NABCD

    N(Need)需求 经发现,很多人在理发时都要经过漫长的排队等待时间,这些时间也就因此白白浪费掉了,而且一些理发店也会因个别顾客不愿等待而损失客源.对此,我们设计出了这款小软件——理了么,一款专门为理 ...

  9. 通过TCPView工具查看foxmail用exchange方式连接exchange时用什么端口

    TCPView下载地址 https://docs.microsoft.com/zh-cn/sysinternals/downloads/tcpview

  10. matlab-单位圆内射线数次反射

    转载自 https://zhidao.baidu.com/question/2268408219692883828.html 先贴代码和放图,然后我再做出一点解释(其实只是觉得这个思路好厉害,所以想保 ...