博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
TOJ 2703: Cow Digit Game
阅读量:6681 次
发布时间:2019-06-25

本文共 2002 字,大约阅读时间需要 6 分钟。

2703: Cow Digit Game 分享至QQ空间

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

简单的博弈,sg函数

把一个数减去这个数非0的最大值或者最小值,分析其必胜

#include 
#include
using namespace std;const int N=1e6+10;int sg[N];int main(){for(int i=1;i<=1e6;i++){int ma=0,mi=9,t=i;while(t){ int b=t%10; if(b){ ma=max(b,ma); mi=min(b,mi);} t/=10;}sg[i]=(sg[i-ma]&sg[i-mi])^1;}int t;scanf("%d",&t);while(t--){ int n; scanf("%d",&n); printf("%s",sg[n]?"YES\n":"NO\n");}return 0;}

 

转载于:https://www.cnblogs.com/BobHuang/p/7113372.html

你可能感兴趣的文章
思科交换机镜像端口介绍配置
查看>>
独家揭秘语音视频聊天室开发顶尖制作教程
查看>>
冲向大牛之安卓:学习界面怎么在程序中画出来
查看>>
.net 签名加密实现的一种简单方法
查看>>
数据结构 试探法算法学习笔记
查看>>
nomad安装
查看>>
我的友情链接
查看>>
MySQL主备复制数据不一致的情况
查看>>
CU3ER非常Cool的3D效果的Flash Slider
查看>>
中财讯 爆遍历目录漏洞
查看>>
MongoDB 数据库备份脚本
查看>>
Linux常用命令
查看>>
10、《每天5分钟玩转Docker容器技术》学习-Docker命令之本地镜像管理
查看>>
shell脚本:输出昨天的日期
查看>>
corosync+pacemaker做高可用web集群
查看>>
mysql中各个模块如何协同工作
查看>>
MyEclipse - 在tomcat6里面配置tomcat7
查看>>
less新手入门(五)—— CssGuards、循环、合并
查看>>
我的友情链接
查看>>
当sd卡不存在时,保存文件到手机上
查看>>