nyoj137 取石子(三) 楼教主男人八题之一

时间:2023-03-09 23:38:05
nyoj137 取石子(三) 楼教主男人八题之一

思路:一堆时,N态。两堆时,当两堆数量相同,P态,不同为N态。三堆时,先手可以变成两堆一样的,必胜N态。

此时可以总结规律:堆数为偶数可能且石子数都是两两相同的,为P态。分析四堆时,当四堆中两两数量一样的情况是P态,有一些数量不一样的情况:x < y < z < k , 可以通过拿k并分配剩下的石子,让四堆两两相同,即转换为P态。当五堆时,先手一定可以变成四堆并让四堆中的石子数两两相同。

至此,找到规律了:当n为奇数,必胜,当n为偶数且石子数两两对应为P态,否则为N态。

AC代码

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <utility>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#define eps 1e-10
#define inf 0x3f3f3f3f
#define PI pair<int, int>
typedef long long LL;
const int maxn = 100 + 5;
int cnt[maxn];

int main() {
	int n;
	while(scanf("%d", &n) == 1 && n) {
		memset(cnt, 0, sizeof(cnt));
		int x;
		for(int i = 0; i < n; ++i) {
			scanf("%d", &x);
			cnt[x]++;
		}
		if(n & 1) printf("Win\n");
		else {
			int flag = 0;
			for(int i = 1; i <= 100; ++i) {
				if(cnt[i] & 1) {
					flag = 1;
					break;
				}
			}
			if(flag) printf("Win\n");
			else printf("Lose\n");
		}
	}
	return 0;
}

如有不当之处欢迎指出!