Description

题库链接

给出 \(n\) 个数,让你生成这 \(n\) 个数的一个排列 \(A\) 。定义 \(B_i = \bigoplus\limits_{j=1}^i A_j\) , \(\oplus\) 表示按位异或,使得 \(B\) 单调递增。

\(1\leq n\leq 10^5,1\leq A_i<2^{60}\)

Solution

一个显然的性质是对于一个数 \(p\) ,找到一个数 \(q\) 使得 \(p\oplus q>p\) 首先要满足 \(q\) 的最高位在 \(p\) 中为 \(0\) 。

由这个性质,我们考虑一种贪心:就是对于当前的数找到一个最高位最小的数的最高位在当前的数中为 \(0\) 。作为排列的下一位。

Code

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 100000+5; int n; ll bin[65], a, ans[N];
queue<ll>q[65]; void work() {
scanf("%d", &n);
bin[0] = 1; for (int i = 1; i <= 60; i++) bin[i] = bin[i-1]<<1;
for (int i = 1; i <= n; i++) {
scanf("%I64d", &a);
for (int j = 60; j >= 0; j--)
if (bin[j]&a) {q[j].push(a); break; }
}
ll now = 0;
for (int i = 1, flag = 0; i <= n; i++, flag = 0) {
for (int j = 0; j <= 60; j++)
if (!(now&bin[j])) {
if (q[j].empty()) continue;
now ^= (ans[i] = q[j].front()); q[j].pop(); flag = 1; break;
}
if (flag == 0) {puts("No"); return; }
}
puts("Yes");
for (int i = 1; i <= n; i++) printf("%I64d ", ans[i]);
}
int main() {work(); return 0; }

[Codeforces 925C]Big Secret的更多相关文章

  1. Codeforces 590D Top Secret Task

    D. Top Secret Task time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  2. codeforces 966c//Big Secret// Codeforces Round #477 (Div. 1)

    题意:一个数组,重新打乱后前缀异或和递增.问这样的排列. 将所有元素按照二进制最高位分组.每次选当前前缀和sum的二进制最低的0位,再从分组中挑一个作为答案.先放首1在较低位的再放首1在较高位的总是可 ...

  3. 2018省赛赛第一次训练题解和ac代码

    第一次就去拉了点思维很神奇的CF题目 2018省赛赛第一次训练 # Origin Title     A CodeForces 607A Chain Reaction     B CodeForces ...

  4. CodeForces 496B Secret Combination

    Secret Combination Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u ...

  5. 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 ...

  6. 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination

    题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...

  7. 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, ...

  8. codeforces 496B. Secret Combination 解题报告

    题目链接:http://codeforces.com/problemset/problem/496/B 题目意思:给出 n 位数你,有两种操作:1.将每一位数字加一(当某一位 > 9 时只保存个 ...

  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 ...

随机推荐

  1. Django:form.save()方法

    参考:https://blog.csdn.net/it_yuan/article/details/53580756 背景: 之前的博客是不支持上传文章缩略图的,后来新增了此功能,但是发现修改老的文章时 ...

  2. ASP.NET MVC URL重写与优化(初级篇)-使用Global路由表定制URL

    ASP.NET MVC URL重写与优化(初级篇)-使用Global路由表定制URL 引言--- 在现今搜索引擎制霸天下的时代,我们不得不做一些东西来讨好爬虫,进而提示网站的排名来博得一个看得过去的流 ...

  3. XML字符串反序列化为实体

    JSON反序列化实体 paydata = StringHelper.Base64ToString(paydata); resInfo = JsonConvert.DeserializeObject&l ...

  4. SignalR简单封装

    需求:Asp.Net MVC 开发客户端,实现与服务器端实时通信. 众所周知,Web开发是基于http的请求响应模型,每次刷新都需要客户端(浏览器)主动发起请求,那么,这个问题怎么解?Asp.Net ...

  5. 从 exe.config 读取appSettings 中的配置数据

    右键解决方案,添加引用--> System.Configuration.dll 在exe.config 中添加数据 <appSettings> <add key=" ...

  6. netcore问题总结

    1. webclient在在netcore异步文件下载的时候,下载进度为空,只有最后下载完了,进度才会是100%,但是在netframework中就没有这个问题,异步文件下载进度会正常提醒. 2. n ...

  7. Unity运行时保存prefab的方法一则

    unity编辑器在运行状态时,prefab的apply按钮就消失了,其实此时代码访问的话是有效的. 代码如下,将会给transform的右键增加一个save prefab的选项. using Unit ...

  8. series dataframe 的 idxmax()

    返回最大值的索引

  9. 《Python绝技:运用Python成为顶级黑客》 用Python实现免杀

    1.免杀的过程: 使用Metasploit生成C语言风格的一些shellcode作为载荷,这里使用Windows bindshell,功能为选定一个TCP端口与cmd.exe进程绑定在一起,方便攻击者 ...

  10. PHP中使用CURL模拟登录并获取数据实例

    cURL 是一个功能强大的PHP库,使用PHP的cURL库可以简单和有效地抓取网页并采集内容,设置cookie完成模拟登录网页,curl提供了丰富的函数,开发者可以从PHP手册中获取更多关于cURL信 ...