标签:des style http color io os java ar strong
题目链接:
4 2 0 1 4 3
20 1 0 2 3 4
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map> #include<vector> #include<cmath> #include<string> #include<queue> #define eps 1e-9 #define ll long long #define INF 0x3f3f3f3f using namespace std; const int maxn=100000+10; int a[maxn],n,ans[maxn]; bool vis[maxn]; int gao(int k) { int cnt=0; while(k) { k>>=1; cnt++; } return cnt; } int main() { while(~scanf("%d",&n)) { memset(vis,false,sizeof(vis)); for(int i=0;i<=n;i++) scanf("%d",&a[i]); for(int i=n;i>=0;i--) { if(vis[i]) continue; int move=gao(i); int temp=(((1<<move)-1)^i);//找到和i二进制表示互补的数 ans[temp]=i; ans[i]=temp; vis[i]=vis[temp]=true; } ll sum=0; for(int i=0;i<=n;i++) sum+=i^ans[i]; printf("%I64d\n",sum); for(int i=0;i<=n;i++) { if(i==n) printf("%d\n",ans[a[i]]); else printf("%d ",ans[a[i]]); } } return 0; }
标签:des style http color io os java ar strong
原文地址:http://blog.csdn.net/u014303647/article/details/39324251