http://acm.hdu.edu.cn/showproblem.php?pid=5014

从最大的一个数开始找能配对使他们的异或值最大的一个数

最后输出

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL; int s[100005],tran[100005];
bool vis[100005];
int tr(int x)
{
int cnt = 0;
while(x){
cnt++;
x>>=1;
}
return (1<<cnt) - 1;
}
int main(){
int n;
while(~scanf("%d",&n)){
for(int i=0;i<=n;i++){
scanf("%d",&s[i]);
}
clr0(vis);
LL ans = 0;
for(int x = n;x >= 0;--x){
if(!vis[x]){
vis[x] = true;
int now = 1LL * tr(x);
int y = now^x;//cout<<x<<','<<y<<endl;
if(!vis[y]){
ans += now<<1;
tran[x] = y,tran[y] = x;
vis[y] = true;
}
else
ans += x,tran[x] = x;
}
}
printf("%I64d\n",ans);
for(int x = 0;x <= n;++x)
printf("%d%c",tran[s[x]]," \n"[x == n]);
}
return 0;
}

最新文章

  1. 【Python】个人所得税
  2. 错误集:js解析jQuery.post返回的xml之Could not find action or result
  3. 如何使用SVN管理我们的源代码
  4. python(2)-字符串(2)
  5. 【转】C#绝对新手之C#中的多线程小结
  6. 301重定向与CNAME
  7. 数据库sqlite的使用
  8. JavaScript之共享onload
  9. EasyUI - DataGrid 组建 - [ 删除,修改 ]
  10. jQuery 截取double数据 重新赋值
  11. 关于idea的使用心得
  12. WPF获得全局窗体句柄,并响应全局键盘事件
  13. React-Native采坑总结
  14. JavaScript Dom级别
  15. Centos7的防火墙关闭
  16. Spring Boot 注解配置 day03
  17. token令牌
  18. vue 父组件给子组件传值 Vue父组件给子组件传方法 Vue父组件把整个实例传给子组件
  19. Linux 学习总结(一)
  20. Haskell语言学习笔记(23)MonadReader, Reader, ReaderT

热门文章

  1. 电脑连接树莓派Pi Zero W
  2. oracle 网络环境配置
  3. Fb,tw等emoji相关
  4. go,函数作为参数类型
  5. hdoj Max Sum Plus Plus(DP)
  6. cdoj第13th校赛初赛H - Hug the princess
  7. day3:vcp考试
  8. 无法启动MYSQL服务”1067 进程意外终止”解决的方法——汇总及终极方法
  9. mysql contact_ws函数 字符串被截断问题
  10. [Groovy] 学习Groovy的好网站(内容全面)