The 16th Heilongjiang Provincial Collegiate Programming Contest I ICU4C

题目描述

http://codeforces.com/gym/103107/problem/I

Solution

阶梯 $nim$

能够发现一个车左边有多少空格他就在第几堆

所以我们直接套阶梯 $nim$ 的结论即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#define maxn 1500100
using namespace std;

int n, m, t, a[maxn];

void work() {
cin >> n; int ans = 0;
while (n--) {
cin >> m >> t;
for (int i = 1; i <= m; ++i) cin >> a[i];
a[0] = -1;
for (int i = m - 1, j = 1, k = t - a[m]; ~i; --i) {
if (a[i] + 1 != a[i + 1]) {
if (k & 1) ans ^= j;
k = t - a[i] - (m - i);
j = 1;
}
else ++j;
}
}
cout << (ans ? "Alice" : "Bob") << "\n";
}

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);

int T; cin >> T;
while (T--) work();
return 0;
}