CodeForces 1174D Ehab and the Expected XOR Problem

题意:
给定两个数\(n\)\(x\),构造一个序列,设为\(a[l]\)(\(l\)不确定)
\(1\)\(1\leq a[i]<2^{n}\)
\(2\)、序列中没有子序列异或和为\(0\)\(x\)
\(3\)\(l\)应最长
分析:
\(1\)、设前\(i\)个数字异或和为\(sum_{i}\),则对于\([i,j]\)的异或和为\(sum_{i}⨁sum_{j-1}\),所以我们可以找出\(sum\)数组,满足

\[\forall i,j,sum_{i}\oplus sum_{j}\neq 0\&\&sum_{i}\oplus sum_{j}\neq x\]

\(2\)、异或性质有\(y⨁z=x\),则有\(y⨁x=z\),且对于任意一个数\(y\)\(z\)是惟一的。且由于\(y\)\(z\)在二进制下是不可能超过\(2^{n}\)的,因此,相对立的\(y\)\(z\)\(2^{n}\)内成对存在,设\(i\)\(1\)开始遍历到\(2^{n}\),我们与将\(i\)对立的数标记即可,我们可以得到\(sum\)数组
\(3\)\(a[i]=sum[i]⨁sum[i-1]\),输出数组即可

#pragma GCC optimize(3, "Ofast", "inline")

#include <bits/stdc++.h>

#define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define int ll
#define ls st<<1
#define rs st<<1|1
#define pii pair<int,int>
using namespace std;
const int maxn = (ll) 5e5 + 5;
const int mod = 1000000007;
const int mod2 = 1000000006;
const int inf = (ll) 1e9 + 5;
bool vis[maxn];

signed main() {
    start;
    int n, x;
    cin >> n >> x;
    vis[x] = vis[0] = true;
    vector<int> ans;
    ans.push_back(0);
    for (int i = 1; i < (1 << n); ++i)
        if (!vis[i]) {
            ans.push_back(i);
            vis[i ^ x] = true;
        }
    cout << ans.size() - 1 << '\n';
    for (int i = 1; i < ans.size(); ++i)
        cout << (ans[i - 1] ^ ans[i]) << ' ';
    return 0;
}

转载于:https://www.cnblogs.com/F-Mu/p/11609577.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值