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后和给 ...
随机推荐
- 【tensorflow】pip 安装失败的原因
linux系统旧版本: pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27- ...
- Python-sys模块,异常
习题1:题目:给一个不多于5位的正整数,要求:一.求它是几位数,二.逆序打印出各位数字. #encoding=utf-8 while True: try: num=int(raw_input(&quo ...
- Git本地仓库与远程github同步的时候提示fatal: remote origin already exists 错误解决办法
Git本地仓库与远程github同步的时候提示fatal: remote origin already exists 错误解决办法 1.git在本地的电脑创建了仓库,要远程同步github的仓库.使用 ...
- iOS可执行文件__TEXT段限制 以及 Android 65K函数限制
1.先看下苹果关于 .ipa上传的大小规定: 最大构建版本文件大小 解压 XXX.ipa size Payload/xxx.app/xxx 32位 32位 + 64位 有些2dx.u3d游戏 或是 ...
- python3.4学习笔记(八) Python第三方库安装与使用,包管理工具解惑
python3.4学习笔记(八) Python第三方库安装与使用,包管理工具解惑 许多人在安装Python第三方库的时候, 经常会为一个问题困扰:到底应该下载什么格式的文件?当我们点开下载页时, 一般 ...
- pbs 作业管理命令
PBS 提供4 条命令用于作业管理. (1) qsub 命令—用于提交作业脚本 命令格式: qsub [-a date_time] [-c interval] [-C directive_prefix ...
- 一些应该使用mongodb或者其他文档存储而不是redis或mysql、oracle json的情形(最近更新场景)
通常来说,我们应该使用应用的特性而不是自己的爱好或者规定而去选择一种合适的组件,选择的标准应该是这个组件最适合或者本身其设计就是为了解决这个问题,而不是这个组件能够做这事情为标准.就拿存储来说,任何时 ...
- 从Oracle到MySQL,余额宝云实践分享
原文链接:http://www.csdn.net/article/2013-11-/2817426-interview-financial-case-yuerbao-aliyun07 余额宝.百度百发 ...
- C++ tinyXML的使用和字符编码转换
转载:http://jetyi.blog.51cto.com/1460128/761708/ 关于tinyxml使用的文档有很多(这篇文章就写的很好),这里仅提一下字符编码的转换问题,如果你不熟悉字符 ...
- 常用maven命令总结
常用Maven命令: mvn -v //查看版本 mvn archetype:create //创建 Maven 项目 mvn compile //编译源代码 mvn test-compile //编 ...