TZOJ 2703 Cow Digit Game(sg博弈)
描述
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博弈)的更多相关文章
- TOJ 2703: Cow Digit Game
2703: Cow Digit Game Time Limit(Common/Java):1000MS/10000MS Memory Limit:65536KByte Total Submit ...
- BZOJ3404: [Usaco2009 Open]Cow Digit Game又见数字游戏
3404: [Usaco2009 Open]Cow Digit Game又见数字游戏 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 47 Solved ...
- 3404: [Usaco2009 Open]Cow Digit Game又见数字游戏
3404: [Usaco2009 Open]Cow Digit Game又见数字游戏 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 72 Solved ...
- 洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game
洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game 题目描述 Bessie is playing a number game against Farmer John, ...
- UVA12293 Box Game —— SG博弈
题目链接:https://vjudge.net/problem/UVA-12293 题意: 两人玩游戏,有两个盒子,开始时第一个盒子装了n个球, 第二个盒子装了一个球.每次操作都将刷量少的盒子的球倒掉 ...
- UVA1482 Playing With Stones —— SG博弈
题目链接:https://vjudge.net/problem/UVA-1482 题意: 有n堆石子, 每堆石子有ai(ai<=1e18).两个人轮流取石子,要求每次只能从一堆石子中抽取不多于一 ...
- HDU 1848(sg博弈) Fibonacci again and again
Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
- [USACO09OPEN]牛的数字游戏Cow Digit Game 博弈
题目描述 Bessie is playing a number game against Farmer John, and she wants you to help her achieve vict ...
- 【博弈论】【SG函数】bzoj3404 [Usaco2009 Open]Cow Digit Game又见数字游戏
#include<cstring> #include<cstdio> #include<algorithm> #include<set> using n ...
随机推荐
- node vue
官网 ECMAScript 6 Node.Js WebPack Vue.js Vuex Vue-loader (类比css-loader,是webpack中用于处理.vue文件的) vue-route ...
- MAP File
https://warpproject.org/trac/wiki/howto/Linker_scripts_MAP_files Description A MAP file is an output ...
- selenium常用的API
打开浏览器 driver.get("http://www.baidu.com") 最大化浏览器 driver.maximize_window() 关闭浏览器 driver.quit ...
- FTP上传文件,报错java.net.SocketException: Software caused connection abort: recv failed
FTP上传功能,使用之前写的代码,一直上传都没有问题,今天突然报这个错误: java.net.SocketException: Software caused connection abort: re ...
- MPICH2简单的安装配置总结
./configure -prefix=/home/mpi/mpich2 make make install 用命令export PATH /home/mpi/mpich2/bin:$PATH,但我是 ...
- C语言博客作业4--数组
C语言博客作业4--数组 1.本章学习总结 1.1思维导图 请以思维导图总结本周的学习内容,如下图所示: 1.2本章学习体会及代码量学习体会 1.2.1学习体会 描述本周学习感受,也可以在这里提出你不 ...
- springboot学习一:快速搭建springboot项目
1.idea创建springboot工程 JDK选择1.8以上的版本 选择springboot的版本和添加配置项 新建一个HelloController,测试 访问 http://localhost: ...
- python爬虫爬取京东、淘宝、苏宁上华为P20购买评论
爬虫爬取京东.淘宝.苏宁上华为P20购买评论 1.使用软件 Anaconda3 2.代码截图 三个网站代码大同小异,因此只展示一个 3.结果(部分) 京东 淘宝 苏宁 4.分析 这三个网站上的评论数据 ...
- (转)Android 只开启一个Activity实例
在一个Activity中,多次调用startActivity()来启动另一个Activity,要想只生成一个Activity实例,方法有两种. 方法一:设置起动模式 一个Activity有四种启动模式 ...
- LevelDB源码分析-Version
Version VersionSet类 VersionSet管理整个LevelDB的当前状态: class VersionSet { public: // ... // Apply *edit to ...