HDU 5014 number sequence (XOR hexadecimal problem)

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 5014




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
Source2014 ACM/ICPC Asia Regional Xi 'an online


Ideas:

Try to find 2 ^ X-1, IQ is really anxious!

In the end, it can all be different or 11111 ...... (All binary bits are 1)

So the sum of eventually exclusive or is N * (n + 1 );


The Code is as follows:

#include <cstdio>#include <cstring>#define MAXN 100017typedef __int64 LL;int a[MAXN], vis[MAXN];int main(){    LL n;    while(~scanf("%I64d",&n))    {        memset(vis,-1,sizeof(vis));        for(int i = 0; i <= n; i++)        {            scanf("%d",&a[i]);        }        int m = 1;        while(m < n)//2^x-1        {            m = m*2+1;        }        for(int i = n; i >= 0; i--)        {            if(i <= m/2)                m/=2;            if(vis[i] == -1)            {                vis[i] = i^m;                vis[i^m] = i;            }        }        LL ans = n*(n+1);        printf("%I64d\n",ans);        for(int i = 0; i < n; i++)        {            printf("%d ",vis[a[i]]);        }        printf("%d\n",vis[a[n]]);    }    return 0;}


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
 
Source2014 ACM/ICPC Asia Regional Xi 'an online

HDU 5014 number sequence (XOR hexadecimal problem)

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.