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)