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. js ParseUrl

    js ParseUrl function parseURL(url) { var a = document.createElement('a'); a.href = url; return { sou ...

  2. Gviz

    1) Introduction 为了理解基因组数据,通常旨在在基因组浏览器中绘制这样的数据,以及各种基因组注释特征,例如基因或转录物模型,CpG岛,重复区域等.这些功能可以从ENSEMBL或UCSC等 ...

  3. byte,short,int,long数据之间的倍数关系

    基本数据类型 byte   =  -128和127------------------------------------------------------------2的8次方,1个字节 shor ...

  4. sign和token设计

    签名设计 对于敏感的api接口,需使用https协议 https是在http超文本传输协议加入SSL层,它在网络间通信是加密的,所以需要加密证书. https协议需要ca证书,一般需要交费. 签名的设 ...

  5. java和数据结构的面试考点

    目标:不要有主要的逻辑错误.2遍以内bug free.注意代码风格 不要让面试官觉得不懂规矩 Java vs C++ Abstract class vs interface  pass by refe ...

  6. 排序矩阵中的从小到大第k个数 · Kth Smallest Number In Sorted Matrix

    [抄题]: 在一个排序矩阵中找从小到大的第 k 个整数. 排序矩阵的定义为:每一行递增,每一列也递增. [思维问题]: 不知道应该怎么加,因为不是一维单调的. [一句话思路]: 周围两个数给x或y挪一 ...

  7. MQ基础概念和介绍

    一.中间件 MQ是一种中间件产品,至于什么是中间件,中间件能干什么,参见以下链接: http://baike.baidu.com/view/23710.htm 二.WebSphere MQ的原理 We ...

  8. python中的日志模块logging

    1.日志级别5个: 警告Warning 一般信息Info  调试 Debug  错误Error 致命Critical 2.禁用日志方法 logging.disable(logging.DEBUG) 3 ...

  9. [Eclipse]Eclipse里对XML进行注释的快捷键

    eclipse中编辑java或C/C++文件时,注释的快捷键均为 "CTRL + / ",编辑xml文件时,该快捷键无效. eclipse 针对 XML 注释:CTRL + SHI ...

  10. 处理No CPU/ABI system image for target的方法

    处理No CPU/ABI system image for target的方法 最近菩提搭建完成Android开发环境后,在创建安卓模拟器的时候遇到了问题.这个问题就是图片中显示的no CPU/ABI ...