【LOJ】#2210. 「HNOI2014」江南乐

LOJ#2210. 「HNOI2014」江南乐

感觉是要推sg函数

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

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

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

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

其中\(\lfloor \frac{N}{i}\rfloor + 1\)\(N - i\lfloor \frac{N}{i} \rfloor\)

\(\lfloor \frac{N}{i}\rfloor\)\(i - (N - i\lfloor \frac{N}{i} \rfloor)\)

由于\(N\)\(\lfloor \frac{N}{i}\rfloor\)奇偶性确定了,我们只要枚举两种不同奇偶性的\(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('\n')
#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;
}

转载于:https://www.cnblogs.com/ivorysi/p/11097893.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值