[Poi2000]条纹

题目分析

BZOJ 2940
可以转化为每次取,c, z, n个石子,并将剩下石子分成任意两堆。

这样我们可以根据上述预处理 SG 函数就行了。

code

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
#define N 100010
#define M 1010

using namespace std;
int c, z, n, m, SG[M];
bool vis[M];

int read() {
	int s = 0, f = 0; char ch = getchar();
	while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
	while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
	return f ? -s : s;
}

int main() {
	c = read(), z = read(), n = read();
	for (int i = 1; i <= 1000; i++) {
		memset(vis, 0, sizeof vis);
		if (i >= c)
			for (int j = 0; j <= i - c; j++)
				vis[SG[j] ^ SG[i - c - j]] = 1;
		if (i >= z) 
			for (int j = 0; j <= i - z; j++)
				vis[SG[j] ^ SG[i - z - j]] = 1;
		if (i >= n)
			for (int j = 0; j <= i - n; j++)
				vis[SG[j] ^ SG[i - n - j]] = 1;
		for (int j = 0;; j++)
			if (!vis[j]) {
				SG[i] = j;
				break;
			}
	}
	m = read();
	while (m--) {
		int a = read();
		if (SG[a]) puts("1");
		else puts("2");
	}
	return 0;
}
posted @ 2020-09-07 22:30  Kersen  阅读(162)  评论(0编辑  收藏  举报