1. 程式人生 > >Luogu 2575 高手過招-SG函數

Luogu 2575 高手過招-SG函數

cli str font 分享 eve ring std namespace none

Solution

SG函數跑一遍就過了ouo

Code

技術分享圖片
 1 #include<cstring>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #define rd read()
 5 #define cl(a) memset(a, 0, sizeof(a));
 6 using namespace std;
 7 
 8 const int N = 1 << 21;
 9 
10 int SG[N], S[500];
11 int T, n;
12 
13 int
read() { 14 int X = 0, p = 1; char c = getchar(); 15 for(; c > 9 || c < 0; c = getchar()) if(c == -) p = -1; 16 for(; c >= 0 && c <= 9; c = getchar()) X = X * 10 + c - 0; 17 return X * p; 18 } 19 20 void mkSG() { 21 for(int i = 0; i < 20; ++i) SG[i] = 0
; 22 for(int i = 1; i < (1 << 20); ++i) { 23 cl(S); 24 int last = -1, nt; 25 for(int j = 0; j < 20; ++j) if((i >> j) & 1) { 26 if(~last) { 27 nt = i | (1 << last); 28 nt ^= 1 << j; 29 S[SG[nt]] = 1
; 30 } 31 } else last = j; 32 int j = 0; 33 for(; S[j]; ++j); 34 SG[i] = j; 35 } 36 } 37 38 int main() 39 { 40 mkSG(); 41 T = rd; 42 for(; T; T--) { 43 n = rd; 44 int ans = 0; 45 for(int i = 1; i <= n; ++i) { 46 int m = rd, tmp = 0; 47 for(int j = 1; j <= m; ++j) { 48 int x = rd; 49 tmp |= 1 << (20 - x); 50 } 51 ans ^= SG[tmp]; 52 } 53 if(ans) puts("YES"); 54 else puts("NO"); 55 } 56 }
View Code

Luogu 2575 高手過招-SG函數