BZOJ 1982 Moving Pebbles

时间:2021-04-19 08:40:12

首先我们假设只有两堆,

容易发现当且仅当两堆相等时,先手必败

否则先手必胜

然后我们猜测一下原因:

->当两堆相等时,无论先手怎么做,后手总能使两堆相等,且必败态为0,0

推广一下:

当所有的石子堆可以两两配对且配对的两两相等时,先手必败

否则先手必胜

证明一下:

1、当出现两两可以配对且相等的情况时,由两堆相等的情况可以推论,无论先手怎么做,后手总能使局面回到两两配对且相等的情况

2、如果不是两两可以配对且相等的情况时,先手总能使局面变成两两配对且相等

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std; const int maxn=100010;
int n;
int a[maxn]; int main(){
while(scanf("%d",&n)==1){
for(int i=1;i<=n;++i)scanf("%d",&a[i]);
if(n&1){printf("first player\n");continue;}
sort(a+1,a+n+1);
bool f=false;
for(int i=2;i<=n;i+=2){
if(a[i]!=a[i-1]){f=true;break;}
}
if(f)printf("first player\n");
else printf("second player\n");
}return 0;
}