TOJ 2703: Cow Digit Game
2703: Cow Digit Game

Total Submit: 1 Accepted:1
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 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.
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
Hint
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.
Source
简单的博弈,sg函数
把一个数减去这个数非0的最大值或者最小值,分析其必胜
#include <stdio.h>
#include <algorithm>
using namespace std;
const int N=1e6+;
int sg[N];
int main(){
for(int i=;i<=1e6;i++){
int ma=,mi=,t=i;
while(t){
int b=t%;
if(b){
ma=max(b,ma);
mi=min(b,mi);}
t/=;
}
sg[i]=(sg[i-ma]&sg[i-mi])^;
}
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
printf("%s",sg[n]?"YES\n":"NO\n");
}
return ;}
TOJ 2703: Cow Digit Game的更多相关文章
- TZOJ 2703 Cow Digit Game(sg博弈)
描述 Bessie is playing a number game against Farmer John, and she wants you to help her achieve victor ...
- 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, ...
- TOJ 1690 Cow Sorting (置换群)
Description Farmer John's N (1 ≤ N ≤ 10,000) cows are lined up to be milked in the evening. Each cow ...
- [USACO09OPEN]牛的数字游戏Cow Digit Game 博弈
题目描述 Bessie is playing a number game against Farmer John, and she wants you to help her achieve vict ...
- 【BZOJ】【3404】【USACO2009 Open】Cow Digit Game又见数字游戏
博弈论 Orz ZYF 从前往后递推……反正最大才10^6,完全可以暴力预处理每个数的状态是必胜还是必败(反正才两个后继状态),然后O(1)查询……我是SB /******************** ...
- BZOJ 3404: [Usaco2009 Open]Cow Digit Game又见数字游戏(博弈论)
一开始被题意坑了= =,题目是说这个数字的最大和最小,不是个位的最大和最小= = 不知道怎么做只能递推了,必胜态就是存在能到达必败态的,必败态就是只能到达必胜态的 CODE: #include< ...
- 【BZOJ】3404: [Usaco2009 Open]Cow Digit Game又见数字游戏(博弈论)
http://www.lydsy.com/JudgeOnline/problem.php?id=3404 写挫好几次.... 裸的博弈论即可.. #include <cstdio> #in ...
随机推荐
- ReactiveCocoa 响应式函数编程
简介 ReactiveCocoa(简称为RAC),RAC具有函数响应式编程特性,由Matt Diephouse开源的一个应用于iOS和OS X的新框架. 为什么使用RAC? 因为RAC具有高聚合低耦合 ...
- 洛谷 P1774 最接近神的人_NOI导刊2010提高(02)
题目描述 破解了符文之语,小FF开启了通往地下的道路.当他走到最底层时,发现正前方有一扇巨石门,门上雕刻着一幅古代人进行某种活动的图案.而石门上方用古代文写着“神的殿堂”.小FF猜想里面应该就有王室的 ...
- codevs 2919 选择题
时间限制: 1 s 空间限制: 16000 KB 题目等级 : 黄金 Gold 题目描述 Description 某同学考试,在N*M的答题卡上写了A,B,C,D四种答案. 他做完了,又不能交,一 ...
- SQLite基础教程目录
SQLite基础教程目录 SQLite主页 SQLite概述 SQLite -安装 SQLite -命令 SQLite -语法 SQLite -数据类型 SQLite -创建数据库 SQLite -附 ...
- java 使用htmlunit模拟登录爬取新浪微博页面
mport java.io.IOException;import java.net.MalformedURLException;import com.gargoylesoftware.htmlunit ...
- shell脚本,逻辑结构题练习。
awk '/5/{a=1}!a' file2结果:1234解释:第一行 /5/不匹配跳过{a=1},继续!a,此时a没有值属于假取反为真,故输出第一行 第二行 /5/不匹配跳过{a=1},继续!a,此 ...
- 身份证号正则校验(js校验+JAVA校验)
js校验身份证号[15位和18位] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 3 ...
- ios之UISlider
初始化一个Slider UISlider *slider = [[UISlider alloc]initWithFrame:CGRectMake(0, 400,320 , 20)]; 滑块是一个标 ...
- 830. Positions of Large Groups@python
In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...
- WebAssembly MDN简单使用
MDN 就是通过编译器编译完成c后生成的胶水代码 引入js 就能直接调用定义在c或者c++中的函数了 c代码如下: #include <stdio.h> #include <stdl ...