HDU-5014 Number Sequence

Source: Internet
Author: User


Problem descriptionthere is a special number sequence which has n + 1 integers. For each number in sequence, we have two rules:

● AI in [0, N]
● AI = AJ (I = J)

For sequence a and sequence B, the integrating Degree t is defined as follows ("writable" denotes exclusive or ):

T = (A0 rjb0) + (A1 rjb1) + · + (an 1_bn)

(Sequence B shoshould also satisfy the rules described abve)

Now give you a number N and the sequence A. You shoshould calculate the maximum integrating Degree t and print the sequence B.

Inputthere are multiple test cases. Please process till EOF.

For each case, the first line contains an integer N (1 ≤ n ≤ 105), the second line contains A0, A1, A2,...,.

Outputfor each case, output two lines. the first line contains the maximum integrating Degree t. the second line contains N + 1 integers B0, B1, B2 ,..., bn. there is exactly one space between Bi AND Bi + 1 (0 ≤ I ≤ n-1) . Don't ouput any spaces after bn.

Sample Input
 
42 0 1 4 3

Sample output
 201 0 2 3 4 Question: Find the two [0, N] in the order of the maximum values of two or two differences or the sum: Calculate a regular question. For example, the maximum number that can be exclusive or reached is 111, so there are () and (), then we will push down the two solutions in turn, for example, the values of and 5 are, 
 # include 
    
      # include 
     
       # include 
      
        # include 
       
         # include 
        
          typedef _ int64 ll; // typedef long ll; using namespace STD; const int maxn = 100005; ll ans [maxn]; int N; int CAL (INT m) {int Len = 0; while (m) {M >>= 1; Len ++;} return Len;} ll Init (INT m) {ll sum = 0; while (M> = 0) {int Len = CAL (m); LL max = (LL) (1 
          
          

HDU-5014 Number Sequence

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.