codeforces 966c//Big Secret// Codeforces Round #477 (Div. 1)
题意:一个数组,重新打乱后前缀异或和递增。问这样的排列。
将所有元素按照二进制最高位分组。每次选当前前缀和sum的二进制最低的0位,再从分组中挑一个作为答案。先放首1在较低位的再放首1在较高位的总是可行的。首1都在同一位的先放哪个都是一样的。
//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <bitset>
using namespace std;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon;
lon n,arr[SZ],ans[SZ];
vector<lon> vct[];
lon one=; void init()
{
cin>>n;
for(lon i=;i<n;++i)
{
cin>>arr[i];
for(lon j=;j>=;--j)
{
if(arr[i]&(one<<j))
{
vct[j].push_back(arr[i]);
break;
}
}
}
} bool work()
{
lon cur=;
for(lon i=;i<n;++i)
{
bool ok=;
for(lon j=;j<;++j)
{
if((cur&(one<<j))==&&vct[j].size())
{
cur^=(ans[i]=vct[j].back());
vct[j].pop_back();
ok=;
break;
}
}
if(!ok)return ;
}
return ;
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
//for(;scanf("%d",&n)!=EOF;)
{
init();
if(!work())cout<<"No"<<endl;
else
{
cout<<"Yes"<<endl;
for(lon i=;i<n;++i)
{
if(i)cout<<" ";
cout<<ans[i];
}cout<<endl;
}
}
return ;
}
codeforces 966c//Big Secret// Codeforces Round #477 (Div. 1)的更多相关文章
- 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination
题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
随机推荐
- RocketMQ 2主2从 集群搭建
安装环境 jdk1.7 alibaba-rocketmq-3.2.6.tar.gz VM虚拟机redhat6.5-x64:192.168.1.201 192.168.1.202 192.168.1. ...
- Python: 类中为什么要定义__init__()方法
学习并转自:https://blog.csdn.net/geerniya/article/details/77487941 1. 不用init()方法定义类 定义一个矩形的类,目的是求周长和面积. c ...
- loj10009 P1717 钓鱼
P1717 钓鱼 贪心+优先队列 先枚举最后走到哪个湖,然后用优先队列跑一遍贪心即可 #include<iostream> #include<cstdio> #include& ...
- jenkins 安装 + maven + git部署
1. 安装JDK 2. 安装maven 3. 安装git 4. 安装tomcat tar zxvf apache-tomcat-8.5.14.tar.gz 找到tomcat-->config-- ...
- [Linux 003]——用户和用户组以及 Linux 权限管理(一)
嗬!没想到吧!学习 Linux 的第三天,我们已经开始接触用户管理,用户组管理,以及权限管理这几个逼格满满的关键字.这几个关键字对于前端程序猿的我来说真的是很高大上有木有,以前尝试学 Linux 的时 ...
- SVC(STM32)
这两个都是 system level service,有什么区别呢?…… 手册上说 SVC 这个指令是同步的,而 PendSV 是异步的,请问是什么意思呢?…… 高手路过尽请留言啊
- Python3基础 函数 局部与全局变量同名,各管各的
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- windows下如何解决chrome浏览器左下角总提示'Downloading proxy script'的问题
答:关掉LAN settings中的Automatically detect settings选项和Use automatic configuration script选项,如下图
- PHP获取当前页面的网址
PHP获取当前页面的网址 function GetCurUrl() { $url = 'http://'; if(isset($_SERVER['HTTPS']) AND $_SERVER['HTTP ...
- C#面试题集锦
1.貌似最常用的是 值类型和引用类型,还有 装箱和 http://www.cnblogs.com/Autumoon/archive/2008/08/18/1270685.html http://ww ...