码迷,mamicode.com
首页 > 其他好文 > 详细

UVA - 11892 ENimEN (推理)

时间:2014-08-28 11:29:09      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   color   os   io   strong   for   ar   

Description

bubuko.com,布布扣


  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 ( Tbubuko.com,布布扣100), the number of test cases. Each test begins with an integer N ( Nbubuko.com,布布扣20000) in the first line, the number of heaps followed by N integers ai ( 1bubuko.com,布布扣aibubuko.com,布布扣109), 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;
}

 

UVA - 11892 ENimEN (推理)

标签:des   style   http   color   os   io   strong   for   ar   

原文地址:http://blog.csdn.net/u011345136/article/details/38894639

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!