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后和给 ...
随机推荐
- REST服务安全-双向认证
1. 创建服务器密钥,其密钥库为 d:/mykeys/server.ks,注意keypass和storepass保持一致,它们分别代表 密钥密码和密钥库密码,注意 CN=localhost 中,loc ...
- appium记录
npm uninstall appium -g npm install -g cnpm --registry=https://registry.npm.taobao.org cnpm install ...
- linux常用命令:less 命令
less 工具也是对文件或其它输出进行分页显示的工具,应该说是linux正统查看文件内容的工具,功能极其强大.less 的用法比起 more 更加的有弹性.在 more 的时候,我们并没有办法向前面翻 ...
- chrome谷歌浏览器用这种方式清除缓存比较方便了,必须是调试模式才行
chrome谷歌浏览器用这种方式清除缓存比较方便了 PS:必须是调试模式才行,可以不是手机模式 ,有些低版本浏览器可能没有这个功能. ----------------------------- ...
- CPU负载过高异常排查实践与总结
昨天下午突然收到运维邮件报警,显示数据平台服务器cpu利用率达到了98.94%,而且最近一段时间一直持续在70%以上,看起来像是硬件资源到瓶颈需要扩容了,但仔细思考就会发现咱们的业务系统并不是一个高并 ...
- 干货:Java并发编程系列之synchronized(一)
1. 使用方法 synchronized 是 java 中最常用的保证线程安全的方式,synchronized 的作用主要有三方面: 确保线程互斥的访问代码块,同一时刻只有一个方法可以进入到临界区 保 ...
- 06: linux下python开发环境梳理
1.1 修改~/.bashrc文件 改编终端颜色 alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' # User specific aliases ...
- Python3基础 try-多个指定except与不指定except 简单示例
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- 常用模块之hashlib,subprocess,logging,re,collections
hashlib 什么是hashlib 什么叫hash:hash是一种算法(3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,M ...
- 用 SwitchHosts设置hotst, 用法示例
涉及到本地默认ip(localhost,127.0.0.1)设置关联地址时,使用XAMPP本地服务器时避免自动跳转设置的域名的一些处理方法 打开此文件,把内容修改如下 # Virtual Hosts# ...