Test instructions
is to let you construct a sequence that makes the sequence XOR and maximum, the sequence of N's full permutation, the sequence and calculation of SUM = A[1] ^ 0 + a[2] ^ 1 + a[3] ^ 2 + ... a[n] ^ n
Construct a sequence to make the maximum
Exercises
The strategy is to make as much as 1 of the results of each XOR or out, whereas precedence is taken from the largest n, since N is most likely to have a larger number
Code:
#include<stdio.h>#include<string.h>int Ans[1000005];intMain(){ intN,x; while(scanf("%d", &N) !=EOF) {x= 1; while(x<=N)x=x<<1;x--;memset(Ans, 255, sizeof(Ans)); for(intI=N;I>= 0;I--) { if(Ans[I] != -1) Continue; //printf ("%d\n", x); while((x^I) >N|| Ans[x^I] != -1)x=x>>1; //printf ("%d%d\n", I, x); Ans[x^I] =I, Ans[I] =x^I; }__int64 sum= 0; for(intI= 0;I<=N;I++) {sum+= (I^Ans[I]); }printf("%i64d\n%d",sum, Ans[0]); for(intI= 1;I<=N;I++)printf("%d", Ans[I]);printf("\ n"); }}
Codeforces 288c-polo The Penguin and XOR operation (thinking)