zoukankan      html  css  js  c++  java
  • 【LOJ】#2210. 「HNOI2014」江南乐

    LOJ#2210. 「HNOI2014」江南乐

    感觉是要推sg函数

    发现(lfloor frac{N}{i} floor)只有(O(sqrt{N}))种取值

    考虑把这些取值都拿出来,能取到这个值的(i)是一个区间([l,r])

    如果(r - l + 1 = 1),那么直接算这个数的答案即可((lfloor frac{N}{i} floor)的石子有奇数堆还是偶数堆,(lfloor frac{N}{i} floor + 1)的石子有奇数堆还是偶数堆,异或起来即可)

    如果(r - l + 1 > 1),证明这个区间里既有奇数又有偶数

    其中(lfloor frac{N}{i} floor + 1)(N - ilfloor frac{N}{i} floor)

    (lfloor frac{N}{i} floor)(i - (N - ilfloor frac{N}{i} floor))

    由于(N)(lfloor frac{N}{i} floor)奇偶性确定了,我们只要枚举两种不同奇偶性的(i)计算两种情况的游戏值就可以了

    #include <bits/stdc++.h>
    #define fi first
    #define se second
    #define pii pair<int,int>
    #define mp make_pair
    #define pb push_back
    #define space putchar(' ')
    #define enter putchar('
    ')
    #define eps 1e-10
    #define ba 47
    #define MAXN 100005
    //#define ivorysi
    using namespace std;
    typedef long long int64;
    typedef unsigned int u32;
    typedef double db;
    template<class T>
    void read(T &res) {
        res = 0;T f = 1;char c = getchar();
        while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
        }
        while(c >= '0' && c <= '9') {
        res = res * 10 +c - '0';
        c = getchar();
        }
        res *= f;
    }
    template<class T>
    void out(T x) {
        if(x < 0) {x = -x;putchar('-');}
        if(x >= 10) {
        out(x / 10);
        }
        putchar('0' + x % 10);
    }
    int T,F;
    int sg[100005],N;
    unordered_map<int,int> zz;
    void Process() {
        for(int i = 0 ; i < F ; ++i) {
    	sg[i] = 0;
        }
        for(int x = F ; x <= 100000 ; ++x) {
    	zz.clear();
    	for(int i = 2 ; i <= x ; ++i) {
    	    int r = x / (x / i);
    	    int t = x / i;
    	    if(r - i + 1 == 1) {
    		int k = 0;
    		if((x % r) & 1) k ^= sg[x / i + 1];
    		if((r - (x % r)) & 1) k ^= sg[x / i];
    		zz[k] = 1;
    	    }
    	    else {
    		if(t % 2 == 0) {
    		    if(x & 1) {
    			zz[sg[x / i + 1] ^ sg[x / i]] = 1;
    			zz[sg[x / i + 1]] = 1;
    		    }
    		    else zz[sg[x / i]] = 1;
    		}
    		else {
    		    if(x & 1) {
    			zz[sg[x / i + 1] ^ sg[x / i]] = 1;
    			zz[sg[x / i]] = 1;
    		    }
    		    else zz[sg[x / i + 1]];
    		}
    	    }
    	    i = r;
    	}
    	while(zz.count(sg[x])) sg[x]++;
        }
    }
    void Solve() {
        int a,ans = 0;
        read(N);
        for(int i = 1 ; i <= N ; ++i) {
    	read(a);
    	ans ^= sg[a];
        }
        if(ans) putchar('1'),space;
        else putchar('0'),space;
    }
    int main(){
    #ifdef ivorysi
        freopen("f1.in","r",stdin);
    #endif
        read(T);read(F);
        Process();
        for(int i = 1 ; i <= T ; ++i) {
    	Solve();
        }
        return 0;
    }
    
  • 相关阅读:
    python中特殊参数self的作用
    python中类的初始化案例
    python中类的调用
    Python--网络编程-----struct模块的字节数限制
    Python--网络编程-----解决粘包问题-简单版
    Python--网络编程-----粘包的底层原理分析
    Python--网络编程-----粘包现象
    Python--网络编程-----socket编程示例--模拟ssh远程执行命令
    pycharm下 os.system执行命令返回有中文乱码
    Python--网络编程-----socket编程示例--打电话--加上链接循环
  • 原文地址:https://www.cnblogs.com/ivorysi/p/11097893.html
Copyright © 2011-2022 走看看