Blog of RuSun

\begin {array}{c} \mathfrak {One Problem Is Difficult} \\\\ \mathfrak {Because You Don't Know} \\\\ \mathfrak {Why It Is Diffucult} \end {array}

P3480 [POI2009]KAM-Pebbles

P3480 [POI2009]KAM-Pebbles

注意到个数不能少于前一个的限制,考虑差分,在 $x$ 处取石子相当在差分序列上 $x$ 的石子移动到 $x + 1$ ,即反向的 StairCase 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
33
34
35
36
37
38
39
#include <cstdio>
using namespace std;
template <class Type>
void read (Type &x)
{
char c;
bool flag = false;
while ((c = getchar()) < '0' || c > '9')
c == '-' && (flag = true);
x = c - '0';
while ((c = getchar()) >= '0' && c <= '9')
x = (x << 1) + (x << 3) + c - '0';
flag && (x = ~x + 1);
}
template <class Type, class ...rest>
void read (Type &x, rest &...y) { read(x), read(y...); }
template <class Type>
void write (Type x)
{
x < 0 && (putchar('-'), x = ~x + 1);
x > 9 && (write(x / 10), 0);
putchar('0' + x % 10);
}
const int N = 1e3 + 10;
int n, w[N];
int main ()
{
int T; read(T);
while (T--)
{
read(n);
for (int i = 1; i <= n; ++i) read(w[i]);
for (int i = n; i; --i) w[i] -= w[i - 1];
int s = 0;
for (int i = 1; i <= n; i += 2) s ^= w[n - i + 1];
puts(s ? "TAK" : "NIE");
}
return 0;
}