HDU 2176

http://acm.hdu.edu.cn/showproblem.php?pid=2176

nim博弈的模型。要输出先手第一次取的情况,考虑角度是留给对手必败态

#include <iostream>
#include <cstdio>

using namespace std;

int a[200005];

int main() {
    int m;
    while(~scanf("%d", &m), m) {
        int s = 0;
        for(int i = 0; i < m; i++) {
            scanf("%d", &a[i]);
            s ^= a[i];
        }        
        if(!s) puts("No");
        else {
            puts("Yes");
            for(int i = 0; i < m; i++) {
                int st = s ^ a[i];
                if(st < a[i]) printf("%d %d
", a[i], st);
            }
        }
    }
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/xiaohongmao/p/4547913.html