UVA - 11892 ENimEN (推理)

Description

 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 arrangement assuming both players, play optimal. We believe it has also some benefits for you!

Input

The first line contains T (
T100), the number of test cases. Each test begins with an integer
N ( N20000) in the first line, the number of heaps followed
by N integers ai (
1ai109),
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
题意:有N堆石子,第i堆有ai个,两个人轮流取,每次可以选择一堆石子,取非0个,多个规则是:如果对手没有把这堆取完的话,那么就要继续在这堆取
思路:可以推理数只有当全部为1且为偶数个的话,后手才能赢,否则的话,先手都可以控制到只剩奇数个1的时候,都是先手赢
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 20005;

int main() {
	int t, n;
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		int flag = 0, a;
		for (int i = 0; i < n; i++) {
			scanf("%d", &a);
			if (a > 1)
				flag = 1;
		}
		if (!flag && n % 2 == 0)
			printf("piloop\n");
		else printf("poopi\n");
	}
	return 0;
}

时间: 2024-08-08 20:39:58

UVA - 11892 ENimEN (推理)的相关文章

uva 11892 - ENimEN(推理)

题目链接:uva 11892 - ENimEN 题目大意:给定n堆石子的个数,两人轮流选择石子堆取石子,直到不能取为失败,附加条件,如果前一次操作,即队手的操作,没有将选中石子堆中的石子取完,那么当前操作者必须在该堆中取石子. 解题思路:只要有一个石子堆的个数大于2,那么先手就获得必胜态,可控.对于全是1的情况判断奇偶性. #include <cstdio> #include <cstring> #include <algorithm> using namespace

UVA 11892 ENimEN (简单博弈)

题面: 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 g

11892 - ENimEN(博弈)

UVA 11892 - ENimEN 题目链接 题意:给定n堆石头,两人轮流取,每次只能取1堆的1到多个,如果上一个人取了一堆没取完,那么下一个人必须继续取这堆,取到最后一个石头的赢,问谁赢 思路:简单推理一下,后手只可能在堆数偶数并且都是1的情况下才可能赢 代码: #include <stdio.h> #include <string.h> const int N = 20005; int t, n, a[N]; bool judge() { if (n % 2) return

UVA - 1611 Crane 推理 + 贪心

题目大意:输入一个1-n的排列,要求经过操作将其变换成一个生序序列.操作的规则如下 每次操作时,可以选一个长度为偶数的连续区间,交换前一半和后一半 提示:2n次操作就足够了 解题思路:这句提示是关键,2n次操作,表明每个数最多只需要两次操作. 应该从左到右依次操作过去,先将前面的数安定好了,就可以不用管前面的数了 假设操作到第i个位置,而i这个数刚好在pos这个位置上,现在就要判断一下能否直接将pos上的i经过操作调到i这个位置上 如果 i + (pos - i) * 2 - 1 <= n 就表

uva 1500 - Alice and Bob(推理)

题目连接:uva 1500 - Alice and Bob 题目大意:在黑板上又一个序列,每次操作可以选择一个数减1,或者是合并两个数,一个数被减至1则自动消除,不能操作者输. 解题思路:结论,对于大于1的数可以看成是一个整数s,为消除他们的总操作步数,包括减1以及合并,c为列中1的个数,如果s>2的话,c或者是s为奇数则为必胜,否则必败.若s≤2的话(s=2或者s=0)是,判断c是否为3的倍数,是的话必败,不是的话必胜. 证明:s>2时,s和c均为偶数是为必败态. s为奇数,c为偶数:先手操

UVA 1372 - Log Jumping(推理)

题目链接:1372 - Log Jumping 题意:给定一些n个木板的起始位置和长度k,相重叠的木板可以互相跳跃,求能构成环的最大数量. 思路:先按起始位置排序,然后每次多一个木板就去判断他和前一个和前前一个能不能互相跳跃,如果可以的话就可以多加上这个木板. 代码: #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; #define max(a,b) ((a)

UVA 11246 - K-Multiple Free set(数论推理)

UVA 11246 - K-Multiple Free set 题目链接 题意:一个{1..n}的集合,求一个子集合,使得元素个数最多,并且不存在有两个元素x1 * k = x2,求出最多的元素个数是多少 思路:推理一下, 一开始n个 先要删除k倍的,删除为{k, 2k, 3k, 4k, 5k, 6k...},会删掉多余的k^2,因此在加回k^2倍的数 然后现在集合中会出现情况的只有k^2的倍数,因此对k^2倍的数字看成一个新集合反复做这个操作即可,因此最后答案为n - n / k + n /

uva 1561 - Cycle Game(推理)

option=com_onlinejudge&Itemid=8&page=show_problem&problem=4336" style="">题目链接:uva 1561 - Cycle Game 题目大意:给出一个环,每次从起点開始,能够选择一个权值非0的边移动,移动后减掉权值至少1点. 不能移动的为失败. 解题思路: 1:有0的情况,假设有方向离权值为0的边的步数为奇数,则为必胜.否则必败. 2:无0的情况,奇数边必胜: 3:有1的情况.同

UVA 11024 - Circular Lock(数论+推理)

UVA 11024 - Circular Lock 题目链接 题意:给定一个矩阵,每次能在一行或者一列都加1,问能否构造出满足每个位置%P都等于0的矩阵,P的得到方法为矩阵p所有数字的gcd 思路:推公式啊,一共4个加值的方法,分别为A,B,C,D A + C 加到A位置上a + k1 p,a为原位置差多少为p的倍数 同理 A + D 加到A位置上b + k2 p B + C 加到A位置上c + k3 p B + D 加到A位置上d + k4 p 这样一来消掉就得到a - b - c + d +