bzoj 1982: [Spoj 2021]Moving Pebbles (博弈)

1982: [Spoj 2021]Moving Pebbles

Time Limit: 10 Sec   Memory Limit: 64 MB
Submit: 172   Solved: 118
[ Submit][ Status][ Discuss]

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

HINT

鸣谢lqp18_31..

Source

[ Submit][ Status][ Discuss]


题解:博弈

与poj 1740基本相同,需要注意的是每堆的石子数可能很大,所以要排序后直接统计,不能直接用数组。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define N 100003
using namespace std;
int a[N],n;
int main()
{
	    //freopen("a.in","r",stdin);
		scanf("%d",&n);
		for (int i=1;i<=n;i++) scanf("%d",&a[i]);
		sort(a+1,a+n+1);
		int last=0; bool pd=false;
		for (int i=2;i<=n;i++)
		 if (a[i]!=a[i-1]||i==n) {
		 	int cnt=i-last-1;
		 	if (i==n) cnt++;
		 	last=i-1;
		 	if (cnt&1) {
		 		pd=true;
		 		break;
			 }
		 }
	    if (pd) printf("first player\n");
	    else printf("second player\n");
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值