HDU 1847 Good Luck in CET-4 Everybody!(SG函数)

其实这道题跟HDU 1848一模一样的。。

代码改改就能AC了

#pragma warning(disable:4996)
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 1000;

int pow2[11], SG[1001];
bool vis[N];

void getSG(){
	SG[0] = 0;
	for (int i = 1; i <= N; i++){
		memset(vis, false, sizeof vis);
		for (int j = 0; pow2[j] <= i; j++){
			vis[SG[i - pow2[j]]] = true;
		}
		for (int j = 0; j <= N; j++){
			if (!vis[j]){
				SG[i] = j;
				break;
			}
		}
	}
}

int main(){
	for (int i = 0; i < 11; i++)pow2[i] = 1 << i;
	getSG();
	int n;
	while (~scanf("%d", &n)){
		if (SG[n] == 0)printf("Cici\n");
		else printf("Kiki\n");
	}
	return 0;
}


你可能感兴趣的:(HDU 1847 Good Luck in CET-4 Everybody!(SG函数))