HDU2176 取(m堆)石子游戏(尼姆博弈)

March 09, 2016

题目链接

中文题。

也是求获胜的取法次数。。

#include<cstring>
#include<cstdio>
#include<cstring>
#include<cmath>
#include <vector>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int a[200005];
int main(){
    //freopen("a.txt", "r", stdin);
    int n;
    while(cin >> n && n){
        int sum = 0;
        for(int i = 0; i < n; i++){
            scanf("%d", &a[i]);
            sum ^= a[i];
        }
        if(!sum) cout << "No" << endl;
        else{
            cout << "Yes" << endl;
            for(int i = 0; i < n; i++){
                int k = sum^a[i];
                if(k < a[i]){
                    cout << a[i] << " " << k << endl;
                }
            }

        }

    }
    return 0;
}

Profile picture

Written by Armin Li , a venture capitalist. [Weibo] [Subscribe]