2703: Cow Digit Game

Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByte
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

USACO Open 2009

简单的博弈,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的更多相关文章

  1. TZOJ 2703 Cow Digit Game(sg博弈)

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

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

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

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

  7. 【BZOJ】【3404】【USACO2009 Open】Cow Digit Game又见数字游戏

    博弈论 Orz ZYF 从前往后递推……反正最大才10^6,完全可以暴力预处理每个数的状态是必胜还是必败(反正才两个后继状态),然后O(1)查询……我是SB /******************** ...

  8. BZOJ 3404: [Usaco2009 Open]Cow Digit Game又见数字游戏(博弈论)

    一开始被题意坑了= =,题目是说这个数字的最大和最小,不是个位的最大和最小= = 不知道怎么做只能递推了,必胜态就是存在能到达必败态的,必败态就是只能到达必胜态的 CODE: #include< ...

  9. 【BZOJ】3404: [Usaco2009 Open]Cow Digit Game又见数字游戏(博弈论)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3404 写挫好几次.... 裸的博弈论即可.. #include <cstdio> #in ...

随机推荐

  1. CF1043D Mysterious Crime

    思路: 参考了http://codeforces.com/blog/entry/62797,把第一个序列重标号成1,2,3,...,n,在剩下的序列中寻找形如x, x + 1, x + 2, ...的 ...

  2. ES-windos环境搭建(1)

    前言 由于elasticsearch为Java开发,所以它还依赖Java JDK环境,并且对版本还有要求,需要1.8(含)以上.我们首先来配置Java JDK环境. JDK简介 JDK是Java语言的 ...

  3. 在ABAP里模拟实现Java Spring的依赖注入

    Dependency Injection- 依赖注入,在Java Spring框架中有着广泛地应用.通过依赖注入,我们不必在应用代码里繁琐地初始化依赖的资源,非常方便. 那么ABAP能否从语言层面上也 ...

  4. Luogu P4463 [国家集训队] calc

    WJMZBMR的题果然放在几年后看来仍然挺神,提出了一种独特的优化DP的方式 首先我们想一个暴力DP,先定下所有数的顺序(比如强制它递增),然后最后乘上\(n!\)种排列方式就是答案了 那么我们容易想 ...

  5. 理解Vue

    Vue.js是JavaScript MVVM(Model-View-ViewModel)库,十分简洁,Vue核心只关注视图层,相对AngularJS提供更加简洁.易于理解的API.Vue尽可能通过简单 ...

  6. monkeyrunner之控件ID不存在或重复(转载lynnLi)

    我们在用monkeyrunner进行Android自动化时,通过获取坐标点或控件ID进行一系列操作.由于使用坐标点时,屏幕分辨率一旦更改,则代码中用到坐标的地方都要修改,这样导致代码的复用率较低.因此 ...

  7. shell脚本,一个经典题目。

    [root@localhost wyb]# cat zhuijiu.sh #!/bin/bash #.写一个脚本执行后,输入名字,产生随机数01-99之间的数字. #.如果相同的名字重复输入,抓到的数 ...

  8. document节点的一些个性属性

    <ol> <li>document.head:返回文档的< head>节点:</li> <li>document.body:返回文档的< ...

  9. CentOS7写汇编并编译运行汇编代码

    1.下载nasm编译器 下载地址是https://www.nasm.us/pub/nasm/releasebuilds/ wget https://www.nasm.us/pub/nasm/relea ...

  10. Mac OS X下安装Vue脚手架(vue-cli)

    前言 Vue作为前端三大框架(Angular,React,Vue)之一,号称是最简单,最容易上手的框架,同时也是行内的大趋势,还可以用来开发最火的小程序.具有开发快,双向数据流等特点,有些人认为Vue ...