题意:
n堆石头,你可以从任意一堆取走任意颗石头,然后从这堆石头中取任意颗石头移动到到任意非空堆(比如3 1 1,你可以先在第一堆移除1个石头,然后给2号和3号都移动一个变成0 2 2)。拿完石头的人胜,问先手必胜还是必败。
输入
3 //3堆
2 1 3 //分别有多少石头
2 //2堆
1 1 //分别有多少石头
0 //表示输入结束
输出
1 //第一组数据先手必胜
0 //第二组数据先手必败
思路:
首先假设有偶数堆,且每堆的数量两两相等。无论先手怎么干,后手直接跟着干,一直赖皮就行了,这种情况先手必败。
再假设有偶数堆,每堆数目随机,先手只需要将最大堆和最小堆移动到一样,然后把剩下的补来两两相等,最大那一堆的石头数量书绝对够的,这个可以证明,这时候先手必胜。
再假设有奇数堆,每堆数目随机,先手只需要把最大堆拿光,然后补齐,先手必胜。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <vector>
#include <map>
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ll long long
using namespace std;
int n, m, a[111],temp;
int main(){
while (scanf("%d", &n), n) {
memset(a, 0, sizeof(a));
for (int i = 0; i < n; i++)
scanf("%d", &temp), a[temp]++;
for (int i = 0; i < 102; i++)
if (a[i] % 2) {
printf("1\n");
goto opo;
}
printf("0\n");
opo:;
}
return 0;
}