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后和给 ...
随机推荐
- Oracle 性能调优
在 oracle 中效率排行, 表连接>exist>not exist>in>no in 并且使用in 查询 会有查询条件数量不能超过1000 的限制: 简单提高效率可以使用 ...
- 拉取远程仓库到本地错误The authenticity of host 'github.com (13.229.188.59)' can't be established.
1.个人在github上面创建了仓库,通过本地的git拉取远程仓库到本地报错信息如下: 这是因为Git使用SSH连接,而SSH第一次连接需要验证GitHub服务器的Key.确认GitHub的Key的指 ...
- MySQL Crash Course #03# Chapter 5. 6 排序. BETWEEN. IS NULL
索引 排序检索的数据 SQL 过滤 vs. 应用程序过滤 简单 Where 补充:大小写敏感. BETWEEN. IS NULL Sorting Retrieved Data mysql> SE ...
- LOJ10066 新的开始
LOJ10066 新的开始 prim 典型题.碰到这种情况,只要建一个虚拟节点,和其他的点连边,按题目给权值即可 代码中把n+1当成虚拟节点 懒得写kruskal就用prim了 #include< ...
- vc++引用外部dll时报error LNK2019: 无法解析的外部符号
初学cpp,因为之前装linux下各种软件的时候,知道LD_LIBRARY_PATH可以指定动态库的目录.今天在vc集成log4cpp的时候,编译main时报error LNK2019: 无法解析的外 ...
- Unity3D之预设
预设的两个特性: 1.重用性.可以使我们快速方便的创建大量的重复性资源.这种创建是通过预设的实例化Instance操作来完成的 在Hierarchy视图中将实例物理添加到Assests中,此时图标 ...
- noip2008 真题练习 2017.2.25
不是有很多可以说的,记住不能边算边取min Code #include<iostream> #include<fstream> #include<sstream> ...
- MAC下BurpSuit社区版升级pro版
环境OSX 步骤1. 官网下载社区版v1.7.32https://portswigger.net/burp/communitydownload 安装 2. 下载keygenhttps://down.5 ...
- Zookeeper一致性协议原理Zab
ZooKeeper为高可用的一致性协调框架,自然的ZooKeeper也有着一致性算法的实现,ZooKeeper使用的是ZAB协议作为数据一致性的算法, ZAB(ZooKeeper Atomic Bro ...
- C++中find()函数和rfind()函数的用法
本文转载自http://blog.csdn.net/youxin2012/article/details/9162415 string中 find()的应用 (rfind() 类似,只是从反向查找) ...