hdu 5014 异或序列
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 异或序列的更多相关文章
- HDU 5014 异或之和
http://acm.hust.edu.cn/vjudge/contest/122814#problem/H 这道题就是求异或之和 知识点: a^b = c 等价于 b^c =a 和 a^c = b ...
- HDU 5968 异或密码
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- bzoj 5301: [Cqoi2018]异或序列 (莫队算法)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=5301 题面; 5301: [Cqoi2018]异或序列 Time Limit: 10 Sec ...
- 「luogu4462」[CQOI2018] 异或序列
「luogu4462」[CQOI2018]异或序列 一句话题意 输入 \(n\) 个数,给定\(k\),共 \(m\) 组询问,输出第 \(i\) 组询问 \(l_i\) \(r_i\) 中有多少个连 ...
- P3917 异或序列
P3917 异或序列暴力前缀异或枚举每一个区间,再求和,60分.正解:按每一位来做对于区间[l,r],如果它对答案有贡献,区间中1的个数一定是奇数,可以按每一位取(1<<i)的前缀和,q[ ...
- bzoj 5301 [Cqoi2018]异或序列 莫队
5301: [Cqoi2018]异或序列 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 204 Solved: 155[Submit][Status ...
- BZOJ5301: [Cqoi2018]异或序列(莫队)
5301: [Cqoi2018]异或序列 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 400 Solved: 291[Submit][Status ...
- Loj 2534 异或序列
Loj 2534 异或序列 考虑莫队离线处理.每加一个数,直接询问 \(a[x]\oplus k\) 的前/后缀数目即可,减同理. 利用异或的优秀性质,可以维护异或前缀和,容易做到每次 \(O(1)\ ...
- 【BZOJ5301】【CQOI2018】异或序列(莫队)
[BZOJ5301][CQOI2018]异或序列(莫队) 题面 BZOJ 洛谷 Description 已知一个长度为 n 的整数数列 a[1],a[2],-,a[n] ,给定查询参数 l.r ,问在 ...
随机推荐
- python的可变list和不可变tuple, dict和set
list和tuple 在python中分为可变表和不可变表: 类型 名称 表示方法 可变 list [] 不可变 tuple () list list是可变表,list内部索引从0开始,正整数是正序的 ...
- java public project default private
- 增加路由ip
C:\Windows\system32>route add ip地址 -P 操作完成!
- ORDER BY 子句在视 图、内联函数、派生表、子查询和公用表表达式中无效
SQL语句: select * from (select distinct t2.issue,cashmoney from (select distinct issue from lot_gamepa ...
- Web开发: servlet的session为null?
servlet的session(会话)显示为null,一般是web.xml中配置不对或者在浏览器输入的url不正确造成的. web.xml配置如下: <servlet> <servl ...
- Asp.net中判断是否是指定页面请求的代码示例
//获取请求网址,非法请求,返回主页 if (Request.UrlReferrer != null) { string requstUrl = Request.UrlReferrer.Absolut ...
- 转)MySQL日期与时间函数
-- MySQL日期时间处理函数 -- 当前日期:2017-05-12(突然发现今天512,是不是会拉防空警报) SELECT NOW() FROM DUAL;-- 当前日期时间:2017-05-12 ...
- windows系统如何真正隐藏文件夹[转载]
方法一(推荐)eg:现需隐藏e盘bak目录下的tools文件夹e:\bak\tools运行:cmd键入:attrib +s +a +h +r e:\bak\tools然后,你再进去看e盘bak目录下, ...
- php session阻塞页面分析及优化 (session_write_close session_commit使用)
转: http://www.tuicool.com/articles/bqeeey 首先看下下面代码, session1.php 文件 <?php ini_set('session.save_p ...
- 接触mybatis使用
1.mybatis mybatis是一个自定义sql.存储过程和高级映射的持久层框架,是Apache下的顶级项目. mybatis可以让程序员将主要精力放在sql上,通过mybatis提供的映射方式. ...