1/* 2 Question: A and B are two sequences, defined by the number of [0, N] intervals! 3. Calculate the sum of a [I] ^ B [I] and the maximum value! 4 5 train of thought: If the binary number of The number N has x digits, there must be a number M, so that all the binary values of the N ^ M 6 are 1, that is, from X to 1! In this case, the maximum value is obtained! 7 8 */9 # include <iostream> 10 # include <cstring> 11 # include <cstdio> 12 # include <algorithm> 13 # define n 100005 14 using namespace STD; 15 16 int B [N], vis [N]; 17 18 19 int POS [N]; 20 21 22 int main () {23 int N; 24 while (scanf ("% d", & N )! = EOF) {25 int X, Y; 26 for (INT I = 0; I <= N; ++ I) {27 scanf ("% d", & X ); 28 POS [x] = I; 29} 30 memset (VIS, 0, sizeof (VIS); 31 long sum = 0; 32 for (INT I = N; i> = 0; -- I) {33 Y = x = I; 34 if (vis [x]) continue; 35 int TMP = 1; 36 while (y) {37 x ^ = TMP; 38 TMP <= 1; 39 y> = 1; 40} 41 vis [x] = vis [I] = 1; 42 sum + = 2 * (x ^ I); 43 B [POS [I] = x; 44 B [POS [x] = I; 45} 46 // printf ("% LLD \ n", sum); 47 cout <sum <Endl; 48 printf ("% d", B [0]); 49 for (INT I = 1; I <= N; ++ I) 50 printf ("% d", B [I]); 51 printf ("\ n "); 52} 53 return 0; 54}
2014 network select 5014 number sequence (exclusive or)