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

  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. const int N = 100000+5;
  5. int n; ll bin[65], a, ans[N];
  6. queue<ll>q[65];
  7. void work() {
  8. scanf("%d", &n);
  9. bin[0] = 1; for (int i = 1; i <= 60; i++) bin[i] = bin[i-1]<<1;
  10. for (int i = 1; i <= n; i++) {
  11. scanf("%I64d", &a);
  12. for (int j = 60; j >= 0; j--)
  13. if (bin[j]&a) {q[j].push(a); break; }
  14. }
  15. ll now = 0;
  16. for (int i = 1, flag = 0; i <= n; i++, flag = 0) {
  17. for (int j = 0; j <= 60; j++)
  18. if (!(now&bin[j])) {
  19. if (q[j].empty()) continue;
  20. now ^= (ans[i] = q[j].front()); q[j].pop(); flag = 1; break;
  21. }
  22. if (flag == 0) {puts("No"); return; }
  23. }
  24. puts("Yes");
  25. for (int i = 1; i <= n; i++) printf("%I64d ", ans[i]);
  26. }
  27. 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. asp.net接收传入的数据流

    我们在日常的应用中,都会遇到这样一个问题,就是我们做的asp.NET程序,会收到其它第三方软件传过来的一些信息数据流,当然了一些文本形式的信息,可以采用get或post的方法来接收,可是要是传过来的是 ...

  2. electron-vue 开发环境搭建(Windows环境)

    1.安装 Node.js,一切都基于这个.安装完成后,终端输入 node -v 验证. 2.建立自己的项目目录,然后进入目录. 安装 vue-cli ,终端输入 npm install -g vue- ...

  3. vs2017 修改项目名称

    由于经常接到各种项目需求, 又不想重新搭建框架. 于是便想到直接修改项目名. 话不多说, 上图~ 1 重命名 解决方案 和  项目名称 2 重命名项目的应用程序名和命名空间 3 Ctrl+F 将旧的工 ...

  4. GCC升级问题解决:configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.,mpfr2.4.0

    如果遇到类似问题: configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.,mpfr2.4.0 解决 ...

  5. Jmeter测试计划要素

    Jmeter中一个脚本就是一个测试计划,也是一个管理单元.Jmeter的请求模拟与并发数(设置线程数,一个线程即代表一个虚拟用户)设置都在脚本文件中一起设置. 测试计划要素如下: 1.脚本中测试计划只 ...

  6. 用switch函数根据选择不同的radio出现不同的视图

    html代码: <!DOCTYPE html> <html> <head> <title></title> <style type=& ...

  7. springMvc的执行流程(源码分析)

    1.在springMvc中负责处理请求的类为DispatcherServlet,这个类与我们传统的Servlet是一样的.我们来看看它的继承图 2. 我们发现DispatcherServlet也继承了 ...

  8. chrome下uploadify导致页面崩溃

    解决方法在初始化uploadify之前用timeout来延迟加载 $(function(){     setTimeout(function(){         $('#file_upload'). ...

  9. POJ 1126

    #include <stdio.h> #include <string> #include <iostream> using namespace std; int ...

  10. QuantLib 金融计算——基本组件之 Currency 类

    目录 QuantLib 金融计算--基本组件之 Currency 类 概述 构造函数 成员函数 如果未做特别说明,文中的程序都是 python3 代码. QuantLib 金融计算--基本组件之 Cu ...