洛谷 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 ...
随机推荐
- voltdb数据库持久性,扩展集群
之前在git上下载的voltdb,以及在官网下载的社区版voltdb均不支持持久性事务,和扩展集群,今天下载了企业试用版voltdb,安装过程不再赘述,记录一下我的使用过程 持久性测试 以前的 vol ...
- svn回退到具体的版本
svn回退到具体的版本 找到项目的版本号 命令行中输入相关命令 到指定地点找到项目即可
- docker 部署django项目(nginx + uwsgi +mysql)
最近在学习用docker部署Django项目,经过百折不挠的鼓捣,终于将项目部署成功,爬过好多坑,也发现很多技能需要提高.特此写下随笔与小伙伴们分享,希望能对大家有所启发. docker的理论我就不赘 ...
- Spring Boot 以 war 方式部署
Spring Boot 默认自带了一个嵌入式的 Tomcat 服务器,可以以jar方式运行,更为常见的情况是需要将 Spring Boot 应用打包成一个 war 包,部署到 Tomcat.Jerry ...
- Python内置函数.md
Python3 内置函数 abs(x) 返回一个数的绝对值.参数可以是一个整数或者一个浮点数.如果参数是一个复数,那么将返回它的模. >>> abs(-123456) 123456 ...
- [Java123] JavaBean
https://stackoverflow.com/questions/3295496/what-is-a-javabean-exactly A JavaBean is just a standard ...
- 从ByteBuffer中解析整数
前言 在解析Redis返回的消息中,有类似 $5\r\nredis\r\n的数据返回,当我们解析这种数据的时候,先解析出5这个数字,然后在取后续的5长度的字符串.当时在解析数字这块卡住了,于是看了 ...
- USB协议规范文档简介
USB协议规范文档简介 USB驱动开发必须对USB相关的协议规范有一定程度的了解,理解得越深,遇到的问题就会越少,解决问题的速度也就越快. 工欲善其行,必先利其器.USB协议规范就是USB ...
- Php5.6.31连接sqlserver 2008R2数据库问题sqlsrv(php5.3及以上版本)与mssql(php5.3以前版本)②
Php5.6.31连接sqlserver 2008R2数据库 1.环境配置 Win7(win8.1) 64 +Apache2.4 + PHP5.6.31 + SQL Server 2008 R2数据 ...
- jQuery选择器(上)
一.基本选择器 1.ID选择器 $("#id") 2.类选择器 $(".class") 3.元素选择器 $("element") 4 ...