zoukankan      html  css  js  c++  java
  • codeforces 768 E 变形NIM博弈/手写sg函数

    题意:给你n堆石头,在同一堆石头下不能取两次相同的数目,问能否后手胜

    题解:设一堆石头最多能取k次不同的石头数目,有nim博弈可以知道只要每一堆石头能取的次数异或起来为0则为必败局,则YES

    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    #include <map>
    #include <queue>
    #include <vector>
    #include <cstring>
    #include <iomanip>
    #include <set>
    #include<ctime>
    #include<unordered_map>
    //CLOCKS_PER_SEC
    #define se second
    #define fi first
    #define ll long long
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define Pii pair<int,int>
    #define Pli pair<ll,int>
    #define ull unsigned long long
    #define pb push_back
    #define fio ios::sync_with_stdio(false);cin.tie(0)
    const int N=2e5+10;
    const ull base=163;
    const int INF=0x3f3f3f3f;
    using namespace std;
    int a[70];
    int main(){
        int n;
        fio;
        cin>>n;
        for(int i=1;i<=60;i++){
            a[i]=a[i-1]+i;
        }
        int sg=0;
        for(int i=1;i<=n;i++){
            int x;
            cin>>x;
            for(int j=1;j<=60;j++){
                if(a[j]>x){
                    sg^=(j-1);
                    break;
                }
            }
        }
        if(sg==0){
            cout<<"YES";
        }
        else cout<<"NO";
        return 0;
    }
  • 相关阅读:
    网络编程
    Python之异常处理
    python第31天作业(面向对象高级)
    day01_计算机的基础介绍
    第一章/第二章课后习题
    day12
    day11
    day09-10
    day08
    day07
  • 原文地址:https://www.cnblogs.com/Mrleon/p/9097532.html
Copyright © 2011-2022 走看看