codeforces 925 c big secret
题意:
给你n个数,b[1],b[2],b[3].......,让你重新排列,使a[i]的值递增
a[i]和b的关系:
a[i] = b[1]^b[2]^b[3]^....^b[i];
首先说异或 因为是递增,所以1^0 0^0 1^1都不满足条件
只有0^1满足条件
1^0 == 1 相当于没有增长
0^1 == 1 这才相当于增长了1
再看 a=00 01 01 10
b=00 10 11 10
这两个二进制数a,b进行异或
对于第一位 大家都等于0 异或出来相当于没变
第二位 大家都等于1 异或出来相当于少1
第三位。。。。。
第四位 a第四位等于0 b第四位等于1 两个数异或 相当于b的这一位没有改变
第五位 a第五位等于1 b第五位等于0 两个数异或 b的这一位变成1
所以只要选择a的最高位等于1 b的这一位等于0的情况进行异或
但是为什么要选择最高位:
因为只要最高位进行了增加 比他低的位无论加1还是减1都不会影响异或后的大小关系
可惜就是这样我也没想出来,想到了0和1的异或关系和一位一位去算
但是没做出来 可惜了
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const long long maxn = 2e5+;
const long long N = (long long)<<;
long long a[maxn];
long long b[maxn];
vector<long long> bit[];
int main()
{
long long n,i,j,k;
long long x;
scanf("%lld",&n);
for(i=;i<n;++i)
{
scanf("%lld",b+i);
x = ;
for(j = ;j>=;--j)
{
if((x<<j)&b[i])
{
bit[j].push_back(b[i]);
break;
}
}
}
x = ;
for(i=;i<n;++i)
{
bool flag = false;
for(j=;j<;++j)
{
if(((x&((long long)<<j)) == ) && bit[j].size())
{
a[i] = bit[j][bit[j].size()-];
x ^= bit[j][bit[j].size()-];
bit[j].pop_back();
flag = true;
break;
}
}
if(!flag)
{
printf("No\n");
return ;
}
}
printf("Yes\n");
for(i=;i<n;++i)
printf("%lld ",a[i]);
}
codeforces 925 c big secret的更多相关文章
- 【CodeForces】925 C.Big Secret 异或
[题目]C.Big Secret [题意]给定数组b,求重排列b数组使其前缀异或和数组a单调递增.\(n \leq 10^5,1 \leq b_i \leq 2^{60}\). [算法]异或 为了拆位 ...
- codeforces div2 603 D. Secret Passwords(并查集)
题目链接:https://codeforces.com/contest/1263/problem/D 题意:有n个小写字符串代表n个密码,加入存在两个密码有共同的字母,那么说这两个密码可以认为是同一个 ...
- CodeForces 496B Secret Combination
Secret Combination Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u ...
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)D. Felicity's Big Secret Revealed
题目连接:http://codeforces.com/contest/757/problem/D D. Felicity's Big Secret Revealed time limit per te ...
- 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination
题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...
- Codeforces Round #603 (Div. 2) D. Secret Passwords 并查集
D. Secret Passwords One unknown hacker wants to get the admin's password of AtForces testing system, ...
- codeforces 496B. Secret Combination 解题报告
题目链接:http://codeforces.com/problemset/problem/496/B 题目意思:给出 n 位数你,有两种操作:1.将每一位数字加一(当某一位 > 9 时只保存个 ...
- Codeforces Round #327 (Div. 1) D. Top Secret Task
D. Top Secret Task time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 590D Top Secret Task
D. Top Secret Task time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- 4. 深入 Python 流程控制
除了前面介绍的 while 语句,Python 还从其它语言借鉴了一些流程控制功能,并有所改变. 4.1. if 语句 也许最有名的是 if 语句.例如: >>> x = int(i ...
- Ubuntu12.04下Qt连接MySQL数据库
本文介绍在Ubuntu12.04 (64 bit) 下使用Qt 4.8.2连接MySQL(Ver 14.14 Distrib 5.5.43)数据库. 1.安装 Qt 和 MySQL 若未安装以上软件, ...
- tableView的cell之间间隔显示空白区域
//再要创建的cell中修改frame - (void)setFrame:(CGRect)frame{ frame.origin.x += ; frame.origin.y += ; frame.si ...
- samtools
samtools 用法 samtools <command> [options] command 见以下列表, 每个 command 的 options 也不同 dict faidx in ...
- STL基础2:vector中使用结构体
#include <iostream> #include <vector> #include <numeric> #include <algorithm> ...
- centos配置虚拟用户再也不用那么麻烦了
http://wiki.centos.org/HowTos/Chroot_Vsftpd_with_non-system_users yum install -y vsftpd db4-utils vs ...
- canvas 实现圆环效果
var race = document.getElementById('race'); var cxt = race.getContext('2d'); var ang = 0; var speed ...
- Shader中的lerp
下面解释下什么是lerp的功能: 官方解释 float lerp(float a, float b, float w) { return a + w*(b-a); } 木有看懂 我的解释:把上面的 ...
- clion中资源文件以及头文件的引用
首先在使用clion中没有将文件target就会出现下面的错误 在使用的时候可以默认一下 在以后的使用中如果不需要某个文件时 就可以在CMakeLis.txt文件把它删除掉 在代码界面的最上面出 ...
- ORACLE 导入的问题
1.导入报错 我将ORACLE12.2 导出的文件,导入到ORACLE12.1 . IMP-00010: 不是有效的导出文件, 标头验证失败 解决办法: 修改 dmp 文件版本,使用UEDITOR打开 ...