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;
}

hdu 5014 异或序列的更多相关文章

  1. HDU 5014 异或之和

    http://acm.hust.edu.cn/vjudge/contest/122814#problem/H 这道题就是求异或之和 知识点: a^b = c 等价于 b^c =a 和 a^c = b ...

  2. HDU 5968 异或密码

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  3. bzoj 5301: [Cqoi2018]异或序列 (莫队算法)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=5301 题面; 5301: [Cqoi2018]异或序列 Time Limit: 10 Sec ...

  4. 「luogu4462」[CQOI2018] 异或序列

    「luogu4462」[CQOI2018]异或序列 一句话题意 输入 \(n\) 个数,给定\(k\),共 \(m\) 组询问,输出第 \(i\) 组询问 \(l_i\) \(r_i\) 中有多少个连 ...

  5. P3917 异或序列

    P3917 异或序列暴力前缀异或枚举每一个区间,再求和,60分.正解:按每一位来做对于区间[l,r],如果它对答案有贡献,区间中1的个数一定是奇数,可以按每一位取(1<<i)的前缀和,q[ ...

  6. bzoj 5301 [Cqoi2018]异或序列 莫队

    5301: [Cqoi2018]异或序列 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 204  Solved: 155[Submit][Status ...

  7. BZOJ5301: [Cqoi2018]异或序列(莫队)

    5301: [Cqoi2018]异或序列 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 400  Solved: 291[Submit][Status ...

  8. Loj 2534 异或序列

    Loj 2534 异或序列 考虑莫队离线处理.每加一个数,直接询问 \(a[x]\oplus k\) 的前/后缀数目即可,减同理. 利用异或的优秀性质,可以维护异或前缀和,容易做到每次 \(O(1)\ ...

  9. 【BZOJ5301】【CQOI2018】异或序列(莫队)

    [BZOJ5301][CQOI2018]异或序列(莫队) 题面 BZOJ 洛谷 Description 已知一个长度为 n 的整数数列 a[1],a[2],-,a[n] ,给定查询参数 l.r ,问在 ...

随机推荐

  1. ArcMap导入图层出现General function failure问题

    问题描述: 使用ArcMap的FeatureClassToFeatureClass命令导入图层,出现如下图的错误提示: 解决方法: 参考http://forums.esri.com/thread.as ...

  2. webservice jaxws header验证

    @WebService @HandlerChain public class UserService { ... } package com.xx.ws.header; import org.w3c. ...

  3. SpringMVC的实现过程

    Spring Web MVC 处理Http请求的大致过程: 一旦Http请求到来,DispatcherSevlet将负责将请求分发.DispatcherServlet可以认为是Spring提供的前端控 ...

  4. python 安装scikit!!!

    首先,吐槽一下,真的是折腾好几天,一会更新这个,一会更新那个,总是各种奇葩问题诸如此类: cannot import check-build pip有新版本,需要更新(黄字) 其中scipy出错最多, ...

  5. 【校招面试 之 C/C++】第29题 C/C++ 关键字extern

    1.extern "C" extern "C"的主要作用就是为了能够正确实现C++代码调用其他C语言代码.加上extern "C"后,会指示 ...

  6. 对象之int介绍

    #Auther Bob #--*--conding:utf-8 --*-- #创建两个int的对象,age1和age2 age1 = 10 age2 = int(1) #查看对象的类 print(ty ...

  7. 性能测试需求分析 业务PV量,响应时间、QPS、TPS

    一. 性能测试需求分析 1.1      性能测试需求内容 性能测试需求应包括以下内容: a)    测试场景及用例,用例访问URL: b)   目标接口方法的入参.出参: c)    外部依赖的服务 ...

  8. swift - 代码创建 pickerView 显示或隐藏横线

    import UIKit class VC1: UIViewController { fileprivate lazy var pickerV : UIPickerView = { let v = U ...

  9. ubuntu 操作系统的目录结构

    Ubuntu 系统的目录众多,并且 Ubuntu 系统是不分 C 盘.D 盘等的,但是所有的目录都是在/目录下面的. 一./:根目录,是所有目录的绝对路径的起始点,Ubuntu 中的所有文件和目录都在 ...

  10. DB2频繁出现死锁,常用解决问题的命令

    --DB2频繁出现死锁,常用解决问题的命令db2 get snapshot for locks on sampledb2 get db cfg for sampledb2 update db cfg ...