UVA 11892 ENimEN (简单博弈)
2015-07-12 09:57
155 查看
题面:
11892 ENimEN
In deterministic games no chance is involved, meaning that the final result can be predicted from the
initial arrangement assuming players play optimal. These games are so boring.piloop and poopi are professional gamers. They play games only to study their algorithmic properties.
Their field of expertise is boring games. One of the boring games they often play is Nim. Nim is a
two-player game which is played using distinct heaps, each containing a number of objects (e.g. stones).
Players take turns removing non-zero number of objects from a heap of their choice. The player who
removes the last object will win.
They wonder if they can change the game to make it more fascinating. Would not that be more
interesting if make the rules stricter? For example what if each player is obliged to take objects from
the last non-empty heap as his opponent took objects from. And if there is no such heap, he can choose
one heap freely and take objects from it.ENimEN is their new invented game based on this rule.
If you are interested in ENimEN, write a program to determine the winner given the initial arrange-
ment assuming both players, play optimal. We believe it has also some benefits for you!
Input
The first line contains T(T 100), the number of test cases. Each test begins with an integer
N(N 20000) in the first line, the number of heaps followed by N integersai(1ai10 9), are the number of objects in i-th heap.
Output
If in the optimal strategy the first player is the winner print ‘poopi’ (as he always plays first), otherwise print ‘piloop’. (Quotes for clarity)
Sample Input
2
2
1 1
4
1 2 1 1
Sample Output
piloop
poopi
解题:简单推一下前几组,可以发现只有(1,1),(1,1,1,1),(1,1,1,1,1,1)...时后者才可能赢。也不是简单的找规律,而是在推导过程中根据结果,想原因。这道题是因为先者面对堆1,没有选择,只能直接取掉,而面对非1堆,先者可以选择全部取掉,或者取掉只剩1个,让后者取,故先者可以左右全局,确定全局的步数。只有碰到全1,且1的个数为偶数个时,先者才没有选择的余地。
代码:
11892 ENimEN
In deterministic games no chance is involved, meaning that the final result can be predicted from the
initial arrangement assuming players play optimal. These games are so boring.piloop and poopi are professional gamers. They play games only to study their algorithmic properties.
Their field of expertise is boring games. One of the boring games they often play is Nim. Nim is a
two-player game which is played using distinct heaps, each containing a number of objects (e.g. stones).
Players take turns removing non-zero number of objects from a heap of their choice. The player who
removes the last object will win.
They wonder if they can change the game to make it more fascinating. Would not that be more
interesting if make the rules stricter? For example what if each player is obliged to take objects from
the last non-empty heap as his opponent took objects from. And if there is no such heap, he can choose
one heap freely and take objects from it.ENimEN is their new invented game based on this rule.
If you are interested in ENimEN, write a program to determine the winner given the initial arrange-
ment assuming both players, play optimal. We believe it has also some benefits for you!
Input
The first line contains T(T 100), the number of test cases. Each test begins with an integer
N(N 20000) in the first line, the number of heaps followed by N integersai(1ai10 9), are the number of objects in i-th heap.
Output
If in the optimal strategy the first player is the winner print ‘poopi’ (as he always plays first), otherwise print ‘piloop’. (Quotes for clarity)
Sample Input
2
2
1 1
4
1 2 1 1
Sample Output
piloop
poopi
解题:简单推一下前几组,可以发现只有(1,1),(1,1,1,1),(1,1,1,1,1,1)...时后者才可能赢。也不是简单的找规律,而是在推导过程中根据结果,想原因。这道题是因为先者面对堆1,没有选择,只能直接取掉,而面对非1堆,先者可以选择全部取掉,或者取掉只剩1个,让后者取,故先者可以左右全局,确定全局的步数。只有碰到全1,且1的个数为偶数个时,先者才没有选择的余地。
代码:
#include <iostream> using namespace std; int main() { int t,n,tmp,ans; cin>>t; while(t--) { cin>>n; ans=0; bool flag=true; for(int i=1;i<=n;i++) { cin>>tmp; if(tmp!=1) flag=false; } if(n%2==0&&flag) cout<<"piloop\n"; else cout<<"poopi\n"; } return 0; }
相关文章推荐
- Hibernate Dialect
- Oracle-数据实现竖排打印
- 使用轻量级ORM Dapper进行增删改查
- 理解三层转发原理
- 设计模式---策略模式
- SAP HR工资配置项1---工资计算周期配置
- Python绘制CPU曲线图
- Notepad++中设置Windows、Unix、Mac三种行尾换行符格式间的转换
- macbook air 开机黑屏解决方法
- qibuild的环境配置
- 浅谈Java中随机数的几种实现方式
- layout 分层技巧
- Apache mina -Processor线程逻辑
- atitit.java方法属性赋值and BeanUtils 1.6.1 .copyProperty的bug
- IOS 获取系统照片和拍照
- 树
- POJ 3083 Children of the Candy Corn(bfs+dfs)
- django with mysql (part-1)
- Android GPS HAL详解
- 欢迎使用CSDN-markdown编辑器