Codeforces 862C Mahmoud and Ehab and the xor

来源:互联网 发布:起床困难户闹钟软件 编辑:程序博客网 时间:2024/05/23 15:31

Problem:n个不同的且小于等于1e6的数使得异或和等于x(n<=1e5,x<=1e5)

Idea:
n>2时选择1n3, 1<<18, 1<<19,x^(1<<18)^(1<<19)^res(res=1n3)
n=2 && x=0时无解

Code:

#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