当前位置:网站首页>P2575 master fight

P2575 master fight

2022-07-05 06:19:00 Strezia

Link
sg function
A very clever question , Originally intended to violence pretreatment 2 20 ∗ 20 2^{20}*20 22020 It's a state, but it doesn't write violence , See the problem solution can be transformed into a ladder Nim, great .
 Insert picture description here

Code

int n;
int a[25];
int sg[25];
void solve() {
    
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i++) {
    
        int m;
        cin >> m;
        memset(a, 0, sizeof(a));
        memset(sg, 0, sizeof(sg));
        int ans1 = 0;
        while(m--) {
    
            int x;
            cin >> x;
            a[x]++;
        }
        int tmp = 0;
        int now = 0;
        for(int i = 20; i; i--) {
    
            if(a[i]) {
    tmp++; continue;}
            sg[++now] = tmp;
            tmp = 0;
        }
        sg[++now] = tmp;
        tmp = 0;
        for(int i = 0; i <= now; i += 2)
            ans1 ^= sg[i];
        ans ^= ans1;
    }
    if(ans) cout << "YES\n";
    else cout << "NO\n";
}
原网站

版权声明
本文为[Strezia]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140616367282.html