hdu 5014 异或序列
2024-08-31 00:55:00
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;
}
最新文章
- 【Python】个人所得税
- 错误集:js解析jQuery.post返回的xml之Could not find action or result
- 如何使用SVN管理我们的源代码
- python(2)-字符串(2)
- 【转】C#绝对新手之C#中的多线程小结
- 301重定向与CNAME
- 数据库sqlite的使用
- JavaScript之共享onload
- EasyUI - DataGrid 组建 - [ 删除,修改 ]
- jQuery 截取double数据 重新赋值
- 关于idea的使用心得
- WPF获得全局窗体句柄,并响应全局键盘事件
- React-Native采坑总结
- JavaScript Dom级别
- Centos7的防火墙关闭
- Spring Boot 注解配置 day03
- token令牌
- vue 父组件给子组件传值 Vue父组件给子组件传方法 Vue父组件把整个实例传给子组件
- Linux 学习总结(一)
- Haskell语言学习笔记(23)MonadReader, Reader, ReaderT