ZOJ - 2083 - Win the Game
题目传送:Win the Game
最近正在慢慢体会博弈里面的SG函数的意义
此题是最简单的SG博弈问题,只需打个表就OK了
AC代码:
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <sstream>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
#define LL long long
#define INF 0x7fffffff
using namespace std;
int sg[55];
int vis[55];
void get_sg() {
sg[0] = 0;
sg[1] = 0;
for(int i = 2; i < 55; i ++) {
memset(vis, 0, sizeof(vis));
vis[sg[i - 2]] = 1;
for(int j = 1; j + 2 <= i; j ++) {
vis[sg[j] ^ sg[i - j - 2]] = 1;
}
for(int j = 0;; j ++) {
if(!vis[j]) {
sg[i] = j;
break;
}
}
}
}
int n;
int main() {
get_sg();
//for(int i = 0; i < 55; i ++) cout << sg[i] << " ";
while(scanf("%d", &n) != EOF) {
int SG = 0, t;
for(int i = 0; i < n; i ++) {
scanf("%d", &t);
SG ^= sg[t];
}
if(SG == 0) {
printf("No\n");
}
else printf("Yes\n");
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-21 11:38:49