HDU-1851-A Simple Game
2017-08-31 21:27
239 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1851
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.
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
2
1
5 4
2
1 1
2 2
Sample Output
Yes
No
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.
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
2
1
5 4
2
1 1
2 2
Sample Output
Yes
No
题目分析:
n堆石子,分别有M1,M2,...Mn个石子,每个堆最多取L1,L2...Ln个石头,两个人分别取石子,每次只能在一堆里取,取完最后一个石子的人获胜。 若后手赢(学生),输出Yes。
巴什和 nim的综合问题,sg值是n%(m+1); 也可以求一下sg值.
A Simple Game
Problem DescriptionAgrael 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.
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
2
1
5 4
2
1 1
2 2
Sample Output
Yes
No
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.
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
2
1
5 4
2
1 1
2 2
Sample Output
Yes
No
题目分析:
n堆石子,分别有M1,M2,...Mn个石子,每个堆最多取L1,L2...Ln个石头,两个人分别取石子,每次只能在一堆里取,取完最后一个石子的人获胜。 若后手赢(学生),输出Yes。
巴什和 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 ; } 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; }
相关文章推荐
- HDU 1851 A Simple Game
- hdu 1851 A Simple Game
- hdu 1851 A Simple Game 博弈论
- HDU 1851 A Simple Game
- hdu 1851 A Simple Game(博弈)
- HDU 1851 - A Simple Game
- HDU(1851) A Simple Game (博弈)
- HDU-1851-A Simple Game
- hdu 1851 A Simple Game
- HDU 1848 Fibonacci again and again && HDU 1851 A Simple Game (基础sg函数)
- hdu 1851 A Simple Game Java 水题系列 博弈
- hdu 1851(A Simple Game)(sg博弈)
- hdu1851 A Simple Game
- A Simple Game HDU - 1851
- HDU1851_A Simple Game_求sg
- HDU - 1851 - A Simple Game
- hdu A Simple Game(1851)
- HDOJ 1851 A Simple Game 博弈 SG函数中找规律
- HDU_2580 A simple stone game
- hdu 2486 A simple stone game