Files
python/TangDou/AcWing_TiGao/T5/GameTheory/POJ1704_StaircaseNim_7.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

58 lines
1.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <math.h>
#include <cstdio>
using namespace std;
const int N = 1010;
int a[N];
/*
测试用例:
1 7
5 6 7 9 12 14 17
输出:
i=1,a[7]-a[6]-1=2
i=3,a[5]-a[4]-1=2
i=5,a[3]-a[2]-1=0
i=7,a[1]-a[0]-1=4
Georgia will win
*/
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n, s = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
sort(a + 1, a + n + 1);
/*
n=7
a[1~7] = {5 6 7 9 12 14 17}
a[7]-a[6]-1=2 1号台阶 √
a[6]-a[5]-1=1 2号台阶 ×
a[5]-a[4]-1=2 3号台阶 √
a[4]-a[3]-1=1 4号台阶 ×
a[3]-a[2]-1=0 5号台阶 √
a[2]-a[1]-1=0 6号台阶 ×
a[1]-a[0]-1=0 7号台阶 √
*/
for (int i = 1; i <= n; i += 2) //枚举 奇数阶台阶
{
s ^= a[n - i + 1] - a[n - i] - 1;
printf("i=%d,a[%d]-a[%d]-1=%d\n", i, n - i + 1, n - i, a[n - i + 1] - a[n - i] - 1);
}
//异或和为0,先手必败;否则先手必胜
puts(s == 0 ? "Bob will win" : "Georgia will win");
}
return 0;
}