HDU/HDOJ1851 nim博弈和巴什博弈的结合
来源:互联网 发布:数控编程代码z代表什么 编辑:程序博客网 时间:2024/06/05 22:35
题目:题目链接
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
题目的意思是:两个人玩游戏,老师和Ag,一开始是老师先玩的,游戏的规则是:这里有n堆石子,每一堆的石子数目是ai,每次当一个人拿的时候他可以选择拿一个到bi个,最后拿完石子的那个人获胜。
开始输入的是石子堆数,再者输入ai,bi。求如果Ag赢就输出“Yes”,否则“No”。
分析: 这道题目就是一个Nim和巴什博弈的结合,对每一堆石子来说,都是一个巴什博弈,这样的结果组合起来又是nim博弈。这样就很明显了。每一堆的结果就是一个sg值,这样就OK了。上代码:
#include <iostream>#include <cstdio>#include <string>#include <string.h>#include <map>#include <vector>#include <cstdlib>#include <cmath>#include <algorithm>#include <cmath>#include <queue>#include <set>using namespace std;int main(){ int T; int i,n; int ans,m,l; scanf("%d", &T); while(T--) { scanf("%d", &n); ans=0; for(i = 1; i <= n; i++) { scanf("%d%d",&m,&l); ans = ans^(m % (l+1) ); } if(ans==0) printf("Yes\n");//后取的人胜 else printf("No\n");//先取的人胜 } return 0;}
努力努力...
- HDU/HDOJ1851 nim博弈和巴什博弈的结合
- 巴什博弈+威佐夫博弈+Nim博弈
- 博弈入门---(巴什博弈,威佐夫博弈,nim博弈)
- hdu 1850nim博弈
- hdu 1849 nim博弈
- Hdu 1729 Nim博弈
- Hdu 1730 Nim博弈
- nim博弈 hdu 1849
- hdu 1847 Nim博弈
- HDU 1850 NIM博弈
- HDU 1850 Nim博弈
- hdu 2176 nim博弈
- HDU 5996 Nim博弈
- 组合博弈(NIM博弈和巴什博奕组合) hdu 1851
- HDU 5011Game-多个堆的NIM博弈
- HDU 1536 S-Nim (博弈 sg函数 Nim和)
- [博弈]SG函数的求法和一些结论 NIM博弈
- hdu 1730 sg博弈||nim博弈
- aix 压缩软件及工具库 下载地址
- 巧用OpenCV计算图片序列(矩阵)的直方图
- ++、--操作使用分析
- Effective c++ 笔记—视c++ 为一个语言联邦
- 编程之美 2.18 数组分割
- HDU/HDOJ1851 nim博弈和巴什博弈的结合
- Hibernate中实现模糊查询
- 如何使用VC的预编译技术(转载)
- 位运算
- 写个小程序有效突破SAT词汇关
- mysql添加删除主键
- WPF中拖动控件,实现位置随意摆放
- C++ const 与 指针
- Python字符串统计以及排序