标签:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; vector<int> r[1010]; int g[1010]; void init() { memset(g, -1, sizeof(g)); for(int i = 0; i <= 1005; i++) { r[i].clear(); } } int getSG(int x) { if(g[x] != -1) return g[x]; if(r[x].size() == 0) return 0; int vis[1010]; memset(vis, 0, sizeof(vis)); for(int i = 0; i < r[x].size(); i++) { g[r[x][i]] = getSG(r[x][i]); vis[g[r[x][i]]] = 1; //puts("check"); } for(int i = 0; ; i++) if(!vis[i]) return i; //puts("check"); } int main() { int n; while(~scanf("%d", &n)) { init(); for(int i = 0; i < n; i++) { int m; scanf("%d", &m); for(int j = 1; j <= m; j++) { int v; scanf("%d", &v); r[i].push_back(v); } } int m, v, flag; while(scanf("%d", &m)) { if(m == 0) break; flag = 0; while(m--) { scanf("%d", &v); if(g[v] == -1) g[v] = getSG(v); flag ^= g[v]; } if(flag == 0) puts("LOSE"); else puts("WIN"); } } }
HDU 1524 - A Chess Game(sg函数 + dfs)
标签:
原文地址:http://www.cnblogs.com/lonewanderer/p/5697163.html