Description
2021. Moving Pebbles Two players play the following game. At the beginning of the game they start with n (1<=n<=100000) piles of stones. At each step of the game, the player chooses a pile and remove at least one stone from this pile and move zero or more stones from this pile to any other pile that still has stones. A player loses if he has no more possible moves. Given the initial piles, determine who wins: the first player, or the second player, if both play perfectly. 给你N堆Stone,两个人玩游戏. 每次任选一堆,首先拿掉至少一个石头,然后移动任意个石子到任意堆中. 谁不能移动了,谁就输了...
Input
Each line of input has integers 0 < n <= 100000, followed by n positive integers denoting the initial piles.
Output
For each line of input, output "first player" if first player can force a win, or "second player", if the second player can force a win.
Sample Input
3 2 1 3
Sample Output
first player
题解:
同POJ A New Stone Game 题解见:http://blog.csdn.net/pzler/article/details/23359243
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int n,a[100002];
int main()
{
while(scanf("%d",&n)!=EOF)
{for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
if(n%2==1) printf("first player\n");
else
{sort(a+1,a+n+1);
int i;
for(i=1;i<=n;i=i+2)
{if(a[i]!=a[i+1]) {printf("first player\n");break;}}
if(i>n) printf("second player\n");
}
}
return 0;
}