Number Sequence
Time Limit: 4000/2000 MS (Java/others) memory limit: 65536/65536 K (Java/Others)
Total submission (s): 545 accepted submission (s): 258
Special Judge
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
Question and question:
The result is N * (n + 1). You can see the first five. The rest of the output goes down from the very beginning, and 2 ^ (LEN)-1-I can be output. The Edge tag is calculated by the side (Len is the number of digits in the binary representation of the current number ).
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int len(int n){ int ans=0; while(n) { n>>=1; ans++; } return ans;}int s[100010];int t[100010];int main(){ int n,le,v; __int64 d; while(scanf("%d",&n)!=EOF) { memset(s,-1,sizeof(s[0])*(n+5)); for(int i=0;i<=n;i++) { scanf("%d",&t[i]); } for(int i=n;i>=0;i--) if(s[i]<0) { le=len(i); v=1<<le; v--; s[i]=v-i; s[v-i]=i; } __int64 m=(__int64)n; d=m*(m+1); printf("%I64d\n",d); for(int i=0;i<n;i++) { printf("%d ",s[t[i]]); } printf("%d\n",s[t[n]]); } return 0;}
HDU 5014 Number Sequence)