Create 5724_tc_to_top.cpp

From http://blog.csdn.net/tc_to_top/article/details/51958964
This commit is contained in:
Kirigaya Kazuto 2016-09-19 12:09:20 +08:00 committed by GitHub
parent 2ad2d592ce
commit 656dafdd2e

55
HDOJ/5724_tc_to_top.cpp Normal file
View File

@ -0,0 +1,55 @@
#include <cstdio>
#include <cstring>
int const MAX = 21;
int sg[1 << MAX], vis[MAX];
int get_sg(int sta)
{
memset(vis, false, sizeof(vis));
for(int i = 20; i >= 0; i--)
{
if(sta & (1 << i))
{
int tmp = sta;
for(int j = i - 1; j >= 0; j--)
{
if(!(sta & (1 << j)))
{
tmp ^= ((1 << i) ^ (1 << j));
vis[sg[tmp]] = true;
break;
}
}
}
}
for(int i = 0; i <= 20; i++)
if(!vis[i])
return i;
return 0;
}
int main()
{
memset(sg, 0, sizeof(sg));
for(int i = 0; i < (1 << 20); i++)
sg[i] = get_sg(i);
int T;
scanf("%d", &T);
while(T --)
{
int n, m, p, ans = 0;
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
scanf("%d", &m);
int sta = 0;
while(m --)
{
scanf("%d", &p);
sta |= (1 << (20 - p));
}
ans ^= sg[sta];
}
printf("%s\n", ans ? "YES" : "NO");
}
}