HDU-1851-A Simple Game
来源:互联网 发布:阿里云对个人有什么用 编辑:程序博客网 时间:2024/06/03 21:39
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1851
A Simple Game
Problem Description
Agrael likes play a simple game with his friend Animal during the classes. In this Game there are n piles of stones numbered from 1 to n, the 1st pile has M1 stones, the 2nd pile has M2 stones, ... and the n-th pile contain Mn stones. Agrael and Animal take turns to move and in each move each of the players can take at most L1 stones from the 1st pile or take at most L2 stones from the 2nd pile or ... or take Ln stones from the n-th pile. The player who takes the last stone wins.
After Agrael and Animal have played the game for months, the teacher finally got angry and decided to punish them. But when he knows the rule of the game, he is so interested in this game that he asks Agrael to play the game with him and if Agrael wins, he won't be punished, can Agrael win the game if the teacher and Agrael both take the best move in their turn?
The teacher always moves first(-_-), and in each turn a player must takes at least 1 stones and they can't take stones from more than one piles.
After Agrael and Animal have played the game for months, the teacher finally got angry and decided to punish them. But when he knows the rule of the game, he is so interested in this game that he asks Agrael to play the game with him and if Agrael wins, he won't be punished, can Agrael win the game if the teacher and Agrael both take the best move in their turn?
The teacher always moves first(-_-), and in each turn a player must takes at least 1 stones and they can't take stones from more than one piles.
Input
The first line contains the number of test cases. Each test cases begin with the number n (n ≤ 10), represent there are n piles. Then there are n lines follows, the i-th line contains two numbers Mi and Li (20 ≥ Mi > 0, 20 ≥ Li > 0).
Output
Your program output one line per case, if Agrael can win the game print "Yes", else print "No".
Sample Input
215 421 12 2
Sample Output
YesNo
Problem Description
Agrael likes play a simple game with his friend Animal during the classes. In this Game there are n piles of stones numbered from 1 to n, the 1st pile has M1 stones, the 2nd pile has M2 stones, ... and the n-th pile contain Mn stones. Agrael and Animal take turns to move and in each move each of the players can take at most L1 stones from the 1st pile or take at most L2 stones from the 2nd pile or ... or take Ln stones from the n-th pile. The player who takes the last stone wins.
After Agrael and Animal have played the game for months, the teacher finally got angry and decided to punish them. But when he knows the rule of the game, he is so interested in this game that he asks Agrael to play the game with him and if Agrael wins, he won't be punished, can Agrael win the game if the teacher and Agrael both take the best move in their turn?
The teacher always moves first(-_-), and in each turn a player must takes at least 1 stones and they can't take stones from more than one piles.
After Agrael and Animal have played the game for months, the teacher finally got angry and decided to punish them. But when he knows the rule of the game, he is so interested in this game that he asks Agrael to play the game with him and if Agrael wins, he won't be punished, can Agrael win the game if the teacher and Agrael both take the best move in their turn?
The teacher always moves first(-_-), and in each turn a player must takes at least 1 stones and they can't take stones from more than one piles.
Input
The first line contains the number of test cases. Each test cases begin with the number n (n ≤ 10), represent there are n piles. Then there are n lines follows, the i-th line contains two numbers Mi and Li (20 ≥ Mi > 0, 20 ≥ Li > 0).
Output
Your program output one line per case, if Agrael can win the game print "Yes", else print "No".
Sample Input
215 421 12 2
Sample Output
YesNo
题目分析:
n堆石子,分别有M1,M2,...Mn个石子,每个堆最多取L1,L2...Ln个石头,两个人分别取石子,每次只能在一堆里取,取完最后一个石子的人获胜。 若后手赢(学生),输出Yes。
巴什和 nim的综合问题,sg值是n%(m+1); 也可以求一下sg值.
巴什和 nim的综合问题,sg值是n%(m+1); 也可以求一下sg值.
#include<iostream> #include<cstring> using namespace std; int sg[22],math[22]; int T,num,n,m; void get_sg() { memset(sg,0,sizeof(sg)); int i,j; for(i=1;i<=20;i++) { memset(math,0,sizeof(math)); for(j=1;j<=m;j++) { math[sg[i-j]]=1; } for(j=0;;j++) { if(math[j]==0) { sg[i]=j; break; } } } } int main() { cin>>T; while(T--) { cin>>num; int i; int ans=0; for(i=1;i<=num;i++) { cin>>n>>m; get_sg(); ans^=sg[n]; } if(ans==0) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }
#include<iostream> using namespace std; int main() { int T,num,n,m; cin>>T; while(T--) { cin>>num; int ans=0; for(int i=1;i<=num;i++) { cin>>n>>m; int t=n%(m+1);//每堆石子的sg值。 ans^=t; } if(ans==0) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }
阅读全文
0 0
- HDU 1851 - A Simple Game
- hdu 1851 A Simple Game
- hdu 1851 A Simple Game
- hdu A Simple Game(1851)
- HDU 1851 A Simple Game
- hdu 1851 A Simple Game
- HDU-1851-A Simple Game
- hdu 1851 A Simple Game SG定理
- HDU(1851) A Simple Game (博弈)
- hdu A Simple Stone Game
- hdu 1851 A Simple Game Java 水题系列 博弈
- hdu 1851 A Simple Game (Nim博弈)
- hdu 2486 A simple stone game
- 【hdu 2486】A simple stone game
- HDU 6237 A Simple Stone Game
- HDU 1848 Fibonacci again and again && HDU 1851 A Simple Game (基础sg函数)
- A Simple FPS Game
- UESTC1141 A Simple Game
- 破解最新版的Myeclipse2017ci-6
- Hibernate 简单入门
- char类型转换成int类型的C++实现
- 2017美图点评编程题
- HTTP协议—— 简单认识TCP/IP协议
- HDU-1851-A Simple Game
- 交错01串
- hdu6140
- @Controller和@RestController的区别?
- 基于tomcat的java web项目的请求响应的编解码问题
- Css hack和expression属性
- 创新工场涂鸦移动2018校园招聘测试题
- python列表的append和extend
- 心生莲花,芬芳自来