HDU 4994-Revenge of Nim(博弈论)
来源:互联网 发布:淘宝偷图技巧 编辑:程序博客网 时间:2024/05/18 02:31
Revenge of Nim
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uAppoint description:
Description
Nim is a mathematical game of strategy in which two players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come from the same heap.
---Wikipedia
Today, Nim takes revenge on you. The rule of the game has changed a little: the player must remove the objects from the current head(first) heap. Only the current head heap is empty can the player start to remove from the new head heap. As usual, the player who takes the last object wins.
---Wikipedia
Today, Nim takes revenge on you. The rule of the game has changed a little: the player must remove the objects from the current head(first) heap. Only the current head heap is empty can the player start to remove from the new head heap. As usual, the player who takes the last object wins.
Input
The first line contains a single integer T, indicating the number of test cases.
Each test case begins with an integer N, indicating the number of heaps. Then N integer Ai follows, indicating the number of each heap successively, and the player must take objects in this order, from the first to the last.
[Technical Specification]
1. 1 <= T <= 100
2. 1 <= N <= 1 000
3. 1 <= Ai <= 1 000 000 000
Each test case begins with an integer N, indicating the number of heaps. Then N integer Ai follows, indicating the number of each heap successively, and the player must take objects in this order, from the first to the last.
[Technical Specification]
1. 1 <= T <= 100
2. 1 <= N <= 1 000
3. 1 <= Ai <= 1 000 000 000
Output
For each test case, output “Yes” if the first player can always win, otherwise “No”.
Sample Input
21221 1
Sample Output
YesNo
题意:有 n 个 heap(假设从左至右编号为1~n),每个 heap 上有一些 objects。有两个player,轮流从左至右的 heap 上取走 object(1 <= 取走数 <= 当前heap上的最多objects数),规定当前的 heapi 如果还有object,那么不能取走heapi+1的object,直到把 heapi 的 object 全部取光。
思路:在这个题中,如果存在大于1的堆的话,谁控制了第一个大于一的堆谁赢,如果没有大于一的堆,那就看n的奇偶性从而确定最后一个是谁。
#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>using namespace std;int a[10010];int main(){ int T,n,i,j; int cnt_1;//在第一个大于1的堆出现之前连续1的个数 int cnt_n;//看是否有大于1的堆 scanf("%d",&T); while(T--) { scanf("%d",&n); cnt_1=cnt_n=0; for(i=0; i<n; i++) scanf("%d",&a[i]); for(i=0; i<n; i++) { if(a[i]==1) cnt_1++; else { cnt_n=1; break; } } if(cnt_n==1) { if(cnt_1%2) printf("No\n"); else printf("Yes\n"); } else { if(n%2) printf("Yes\n"); else printf("No\n"); } } return 0;}
0 0
- HDU 4994-Revenge of Nim(博弈论)
- hdu 4994 - Revenge of Nim
- HDU 4994 Revenge of Nim (博弈)
- hdu 4994 Revenge of Nim 博弈
- hdu 4994 Revenge of Nim (博弈)
- hdu 4994 Revenge of Nim(博弈)
- hdu 4994 Revenge of Nim(博弈)
- HDU 4994 Revenge of Nim(博弈)
- HDU 4994 Revenge of Nim(博弈)
- HDU 4994Revenge of Nim(玄学)(Nim问题)
- HDU 4994 Revenge of Nim(组合游戏)
- HDU 4994 Revenge of Nim(简单博弈)
- hdu 4994 Revenge of Nim(尼姆博奕变形)
- HDU 4994 / BC 9B Revenge of Nim
- HDOJ 4994 Revenge of Nim
- 【HDU】5088 Revenge of Nim II 高斯消元
- 【HDU】 5088 Revenge of Nim II 高斯消元
- HDU - 5088 Revenge of Nim II
- Java虚拟机性能管理神器 - VisualVM(9) 排查JAVA应用程序线程死锁
- navigator.userAgent.indexOf来判断浏览器类型
- 25匹马赛跑问题
- Android的px、dp和sp等单位的区别详解
- POJ 3159 Candies(差分约束)
- HDU 4994-Revenge of Nim(博弈论)
- Android开发者必知的Java知识(三) 结合注解分析ActiveAndroid的实现
- python3 导入模块
- JS快捷键
- PRML Charpter 2 Probability Distribution 2.3.5 Sequential estimation讲义摘要
- 解决:AMQ应用部署到weblogic服务器上出现“找不到匹配的方法setLifo"
- CUDA: 使用shared memory
- poj3190
- 【蓝桥杯训练】------2n皇后问题