洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game
洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game
题目描述
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.
贝茜和约翰在玩一个数字游戏.贝茜需要你帮助她.
游戏一共进行了G(1≤G≤100)场.第i场游戏开始于一个正整数Ni(l≤Ni≤1,000,000).游
戏规则是这样的:双方轮流操作,将当前的数字减去一个数,这个数可以是当前数字的最大数码,也可以是最小的非0数码.比如当前的数是3014,操作者可以减去1变成3013,也可以减去4变成3010.若干次操作之后,这个数字会变成0.这时候不能再操作的一方为输家. 贝茜总是先开始操作.如果贝茜和约翰都足够聪明,执行最好的策略.请你计算最后的赢家.
比如,一场游戏开始于13.贝茜将13减去3变成10.约翰只能将10减去1变成9.贝茜再将9减去9变成0.最后贝茜赢.
输入输出格式
输入格式:
* 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
说明
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.
其实,这一堆英文我也没看懂,but,但是,我有翻译器啊,hhh。
不过好像大家都有。
代码
#include<cstdio>
#include<iostream>
bool win[];
int T,n,maxn,minn,x;
int main() {
scanf("%d",&T);
for(int i=; i<=; i++) win[i]=;
for(int i=; i<=; i++) {
int s=i,t;
maxn=-,minn=;
while(s) {
t=s%;
if(t>maxn&&t) maxn=t;
if(t<minn&&t) minn=t;
s/=;
}
if(maxn!=-) win[i]|=(!win[i-maxn]);
if(minn!=) win[i]|=(!win[i-minn]);
}
while(T--) {
std::cin>>x;
if(win[x]) {
puts("YES");
printf("\n");
} else {
puts("NO");
printf("\n");
}
}
}
代,代代代码
洛谷 2953 [USACO09OPEN]牛的数字游戏Cow Digit Game的更多相关文章
- [USACO09OPEN]牛的数字游戏Cow Digit Game 博弈
题目描述 Bessie is playing a number game against Farmer John, and she wants you to help her achieve vict ...
- LuoguP2953 [USACO09OPEN]牛的数字游戏Cow Digit Game(博弈论)
1~9显然,后面平\(A\)过去 #include <iostream> #include <cstdio> #include <cstring> #include ...
- 洛谷——P2952 [USACO09OPEN]牛线Cow Line
P2952 [USACO09OPEN]牛线Cow Line 题目描述 Farmer John's N cows (conveniently numbered 1..N) are forming a l ...
- 洛谷P2950 [USACO09OPEN]牛绣Bovine Embroidery
P2950 [USACO09OPEN]牛绣Bovine Embroidery 题目描述 Bessie has taken up the detailed art of bovine embroider ...
- 洛谷P 1427 小鱼的数字游戏
题目描述 小鱼最近被要求参加一个数字游戏,要求它把看到的一串数字(长度不一定,以0结束,最多不超过100个,数字不超过2^32-1),记住了然后反着念出来(表示结束的数字0就不要念出来了).这对小鱼的 ...
- 洛谷 P2863 [USACO06JAN]牛的舞会The Cow Prom-强连通分量(Tarjan)
本来分好组之后,就确定好了每个人要学什么,我去学数据结构啊. 因为前一段时间遇到一道题是用Lca写的,不会,就去学. 然后发现Lca分为在线算法和离线算法,在线算法有含RMQ的ST算法,前面的博客也写 ...
- 洛谷P2875 [USACO07FEB]牛的词汇The Cow Lexicon
P2875 [USACO07FEB]牛的词汇The Cow Lexicon 题目描述 Few know that the cows have their own dictionary with W ( ...
- 洛谷 P2863 [USACO06JAN]牛的舞会The Cow Prom
传送门 题目大意:形成一个环的牛可以跳舞,几个环连在一起是个小组,求几个小组. 题解:tarjian缩点后,求缩的点包含的原来的点数大于1的个数. 代码: #include<iostream&g ...
- 洛谷——P2863 [USACO06JAN]牛的舞会The Cow Prom
https://www.luogu.org/problem/show?pid=2863#sub 题目描述 The N (2 <= N <= 10,000) cows are so exci ...
随机推荐
- lock free数据结构内存回收技术-hazard pointer
lock free数据结构一般来说拥有比基于lock实现的数据结构更高的性能,但是其实现比基于lock的实现更为复杂,需要处理的难题包括预防ABA问题,内存如何重用和回收等.通常,最简单最有效的处理A ...
- scrapy实战--爬取报刊名称及地址
目标:爬取全国报刊名称及地址 链接:http://news.xinhuanet.com/zgjx/2007-09/13/content_6714741.htm 目的:练习scrapy爬取数据 学习过s ...
- 解决eclipse 文件更新不自动刷新的问题
打开eclipse 1. Window ===> Preferences ===> General ===> Workspace 2. 勾选 1> Refresh using ...
- [book] iOS 8 Swift Programming Cookbook
iOS 8 Swift Programming Cookbook 资源地址 http://pan.baidu.com/s/1c0hn1Gc 书籍介绍 源码截图 书籍截图
- 使用CoreData [2]
使用CoreData [2] 此篇讲解CoreData处理关系型数据. 1. 先创建出Student于Teacher的实体. 2. 确定关系,并修改描述 3. 创建对象,并查看一下关系(Teacher ...
- My Heart Will Go On(我心永恒)
My Heart Will Go On(我心永恒) 歌词(英文) 歌词(中文) 简介:电影<泰坦尼克号>插曲 歌手:Celine Dion(席琳·迪翁) 词作:韦尔·杰宁斯(Wil ...
- 【笔记】select, poll, epool
Select 系统调用: select 轮询监听多个文件描述符的数组,其原理如下(转自:这里): 从用户空间拷贝fd_set到内核空间:注册回调函数__pollwait:遍历所有fd,对全部指定设备做 ...
- ubuntu常见问题排查
1. ubuntu recovery mode read-only 获取写的权限 1.1. 选择fsck check all file systems 进去直接选择YES就可以了 1.2. 选择roo ...
- JS日期比较大小 给定时间和持续时间计算最终时间
/* 往指定时间字符串上加时间间隔,获得新的时间字符串 * startDateStr:开始时间字符串,类似"2015-7-20 17:26:00" * durationN ...
- 算法题:整形数组找a和b使得a+b=n
题目: 数组 A 由 1000 万个随机正整数 (int) 组成,设计算法,给定整数 n,在 A 中找出 a 和 b,使其符合如下等式: n = a + b 解题思路: 1. 1000w个随机正整数占 ...