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. AJPFX关于子类父类中的构造

    1.子父类中的构造函数不存在重写,因为子父类的构造函数名字不一样(重写要求子父类的方法名字一模一样,包括参数列表)2.子类创建对象时会先运行父类的构造函数再运行子类的构造函数.因为每个子类的构造函数的 ...

  2. 洛谷 P3853 [TJOI2007]路标设置

    路标设置 二分枚举"空旷指数", 做法与跳石头类似. #include <iostream> #include <cstdio> #include < ...

  3. MySQL流程控制和存储过程介绍

    /*定义变量方式1:set @变量名=值;方式2:select 值 into @变量名;方式3:declare 变量名 类型(字符串类型加范围) default 值; in参数 入参的值会仅在存储过程 ...

  4. vue使用echarts可视化图形插件

    1.安装echarts:  cnpm/npm i echarts -S 2.main.js中   import echarts from 'echart'    Vue.prototype.$echa ...

  5. vue+element ui项目总结点(六)table编辑当前行、删除当前行、新增、合计操作

    具体属性方法参考官方网站:http://element-cn.eleme.io/#/zh-CN/component/installation <template> <div clas ...

  6. Thread and Peocess

    Thread and Peocess pthread_create() 原型: int pthread_create(pthread_t* thread, pthread_attr_t* attr, ...

  7. Data truncation: Data too long for column 'id' at row 1

    Caused by: java.sql.BatchUpdateException: Data truncation: Data too long for column 'titleimg' at ro ...

  8. Java调用存储过程出现Bug,sql语法错误

    因为SQL Server运行没有正常,检查了传入参数的值,发现问题,然后传入默认参数,解决了问题.

  9. CPP-基础:内部函数应该在当前源文件中说明和定义

    static函数与普通函数作用域不同,仅在本文件.只在当前源文件中使用的函数应该说明为内部函数(static),内部函数应该在当前源文件中说明和定义.对于可在当前源文件以外使用的函数,应该在一个头文件 ...

  10. bootstrap 翻页(对齐的链接)

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...