Codeforces 862C Mahmoud and Ehab and the xor

Problem: P r o b l e m : n n 个不同的且小于等于1e6的数使得异或和等于x (n<=1e5,x<=1e5) ( n <= 1 e 5 , x <= 1 e 5 )

Idea: I d e a :
n>2 n > 2 时选择 1n3 1 ∼ n − 3 , 1<<18 1 << 18 , 1<<19 1 << 19 , x x ^(1<<18)^ (1<<19) ( 1 << 19 ) ^ res(res=1n3) r e s ( r e s = 1 ∼ n − 3 的 异 或 和 )
n=2 n = 2 && x=0 x = 0 时无解

Code: C o d e :

#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define CLR(A, X) memset(A, X, sizeof(A))
#define bitcount(X) __builtin_popcountll(X)
typedef long long LL;
typedef pair<int, int> PII;
const double eps = 1e-10;
const int MOD = 255;
const LL INF = 1e18;
int dcmp(double x) { if(fabs(x) < eps) return 0; return x<0?-1:1; }

const int MAXN = 1e5+5;

int main() {
    int n, x;
    scanf("%d%d", &n, &x);
    if(n==2 && x==0) puts("NO");
    else {
        puts("YES");
        if(n == 1) printf("%d\n", x);
        else if(n == 2) printf("0 %d\n", x);
        else {
            int res = 0, d0 = 1<<18, d1 = 1<<19;
            for(int i = 1; i <= n-3; i++) {
                printf("%d ", i);
                res ^= i;
            }
            printf("%d %d %d\n", d0, d1, d0^d1^x^res);
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值