标签:des style blog color io os java ar strong
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 244 Accepted Submission(s): 126
Special Judge
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; #define N 100005 int suan(int n){ int ans=1; for(int i=1;i<=n;i++) ans*=2; return ans; } main() { int ha[N], n, a[N]; int i, j, k; while(scanf("%d",&n)==1){ memset(ha,0,sizeof(ha)); for(i=18;i>=0;i--){ //寻找2^k中的k 因为以2^k所在位置为l进行匹配操作的,i=18时就已经超过n的最大值了 if(suan(i)<=n){ j=i;break; } } int l=j, r=n; long long ans=0; while(l>0){ 把0---n所有数字进行匹配 int ll; for(ll=r,i=suan(l)-(r-suan(l)+1);i<=suan(l)-1;i++){ ha[i]=ll; ha[ll]=i; ll--; } r=suan(l)-(r-suan(l)+1)-1; if(r<=0) break; for(i=18;i>=0;i--){ if(suan(i)<=r){ l=i;break; } } } if(ha[0]==ha[1]&&ha[0]==0) ha[0]=1,ha[1]=0; //上面while可能跳过1了。。。其实while改一下就行了..懒得改就加上了这个 for(i=0;i<=n;i++){ scanf("%d",&a[i]); } for(i=0;i<=n;i++){ ans+=(ha[i]^i); } printf("%I64d\n",ans); printf("%d",ha[a[0]]); for(i=1;i<=n;i++){ printf(" %d",ha[a[i]]); } cout<<endl; } }
标签:des style blog color io os java ar strong
原文地址:http://www.cnblogs.com/qq1012662902/p/3971901.html