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 ...
随机推荐
- wireshark过滤器
一 概况 本文是对wireshark抓包过滤器, 跟显示过滤器的总结 由于一些未知的原因, 这俩过滤器的语法并不一样! 我大概知道为什么不一样了, 因为这俩出现的顺序不一样, 抓包过滤器先出现的, 可 ...
- int main(int argc,char* argv[]) 的含义和用法
1.基本概念 argc,argv 用命令行编译程序时有用. 主函数main中变量(int argc,char *argv[ ])的含义,有些编译器允许将main()的返回类型声明为void,这已不再是 ...
- Python常用高级函数
一 .匿名函数 有些时候,我们不需要显式的定义函数,可以使用匿名函数临时快速定义函数. lambda x: x * x 关键字lambda表示匿名函数,冒号前面的x表示函数的参数,多个参数用','隔开 ...
- FPGA——按键(二)
直接上源码: module key_led( input sys_clk , //50Mhz系统时钟 input sys_rst_n, //系统复位,低有效 :] key, //按键输入信号 :] l ...
- python大法好——mysql防注入
MySQL 及 SQL 注入 如果您通过网页获取用户输入的数据并将其插入一个MySQL数据库,那么就有可能发生SQL注入安全的问题. 本章节将为大家介绍如何防止SQL注入,并通过脚本来过滤SQL中注入 ...
- python大法好——Python XML解析
Python XML解析 什么是XML? XML 被设计用来传输和存储数据. XML是一套定义语义标记的规则,这些标记将文档分成许多部件并对这些部件加以标识. 它也是元标记语言,即定义了用于定义其他与 ...
- Habits of Considerate People
Habits of Considerate People体贴人的八种习惯哲学家亚瑟·叔本华曾经说过:“蜡之可贵,在于燃烧自己温暖他人,人之可贵,在于屈尊敬贤彬彬有礼”,事实的确如此.善意与体贴能够抚慰 ...
- centos7 根分区扩容
系统安装时候使用的默认分区,根分区只分了50G,使用的是LVM 想把home分区分出来660G给根分区 先查了点资料开搞 由于xfs分区只支持增大,不支持缩小,所以home目前是xfs格式无法进行缩小 ...
- Oracle 11gR2 客户端windows 10安装后PL/SQL配置
操作系统:windows 10 软件:Oracle 11gR2 客户端 (64 bit) PLSQL Developer 13 (64 bit) 注意:PLSQL与oracle客户端版本要一致 1. ...
- 无分类编址(CIDR,Class Inter-Domain-Routing)
CIDR全称是无分类域间路由选择,英文全称是Classless Inter-Domain Routing,大家多称之为无分类编址 CIDR的特点 (1)CIDR消除了传统的A类.B类和C类地址以及划分 ...