2014 network select 5014 number sequence (exclusive or)

Source: Internet
Author: User
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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.