题意:

给你n个数,b[1],b[2],b[3].......,让你重新排列,使a[i]的值递增

a[i]和b的关系:

a[i] = b[1]^b[2]^b[3]^....^b[i];

首先说异或  因为是递增,所以1^0  0^0  1^1都不满足条件

只有0^1满足条件

1^0 == 1   相当于没有增长

0^1 == 1  这才相当于增长了1

再看   a=00 01 01 10

   b=00 10 11 10

这两个二进制数a,b进行异或

对于第一位  大家都等于0  异或出来相当于没变

第二位  大家都等于1  异或出来相当于少1

第三位。。。。。

第四位 a第四位等于0   b第四位等于1  两个数异或  相当于b的这一位没有改变

第五位 a第五位等于1    b第五位等于0 两个数异或  b的这一位变成1

所以只要选择a的最高位等于1     b的这一位等于0的情况进行异或

但是为什么要选择最高位:

因为只要最高位进行了增加    比他低的位无论加1还是减1都不会影响异或后的大小关系

可惜就是这样我也没想出来,想到了0和1的异或关系和一位一位去算

但是没做出来   可惜了

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const long long maxn = 2e5+;
const long long N = (long long)<<;
long long a[maxn];
long long b[maxn];
vector<long long> bit[];
int main()
{
long long n,i,j,k;
long long x;
scanf("%lld",&n);
for(i=;i<n;++i)
{
scanf("%lld",b+i);
x = ;
for(j = ;j>=;--j)
{
if((x<<j)&b[i])
{
bit[j].push_back(b[i]);
break;
}
}
}
x = ;
for(i=;i<n;++i)
{
bool flag = false;
for(j=;j<;++j)
{
if(((x&((long long)<<j)) == ) && bit[j].size())
{
a[i] = bit[j][bit[j].size()-];
x ^= bit[j][bit[j].size()-];
bit[j].pop_back();
flag = true;
break;
}
}
if(!flag)
{
printf("No\n");
return ;
}
}
printf("Yes\n");
for(i=;i<n;++i)
printf("%lld ",a[i]);
}

codeforces 925 c big secret的更多相关文章

  1. 【CodeForces】925 C.Big Secret 异或

    [题目]C.Big Secret [题意]给定数组b,求重排列b数组使其前缀异或和数组a单调递增.\(n \leq 10^5,1 \leq b_i \leq 2^{60}\). [算法]异或 为了拆位 ...

  2. codeforces div2 603 D. Secret Passwords(并查集)

    题目链接:https://codeforces.com/contest/1263/problem/D 题意:有n个小写字符串代表n个密码,加入存在两个密码有共同的字母,那么说这两个密码可以认为是同一个 ...

  3. CodeForces 496B Secret Combination

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

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

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

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

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

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

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

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

  9. Codeforces 590D Top Secret Task

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

随机推荐

  1. 3A - Holding Bin-Laden Captive!

    We all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But rec ...

  2. C# 出现base-64 字符数组的无效长度的解决办法

    最近的一个项目,在传递参数时,在Win2003上正常,在Win7下抛出“base-64 字符数组的无效长度”这样的错误 对比了一下经过Convert.ToBase64String()转换过的参数发现, ...

  3. PAT 甲级1001 A+B Format (20)(C++ -思路)

    1001 A+B Format (20)(20 分) Calculate a + b and output the sum in standard format -- that is, the dig ...

  4. ajax写用户注册

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. 希尔排序和归并排序(java实现)

    希尔排序 希尔排序算法实际上是一种特殊的插入排序,由DL.Shell于1959年提出而得名. 算法思想:希尔排序使数组中任意间隔为h的元素都是有序的,这些数组称为h有序数组,对于每个h,按插入排序进行 ...

  6. is not allowed to connect to this MySQL server解决办法

    GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; myuser:代表你 ...

  7. On the internet, nobody known you are a dog !

  8. Python中的实例方法、类方法、静态方法和普通方法

    为了辨析它们的差别,写了如下代码: class C: def self_method(self, a): return a @classmethod def class_method(cls, a): ...

  9. 关于js的function.来自百度知道的回答,学习了.

    在js中,创建一个函数对象的语法是var myFunction = new Function(arg1,…,agrN, body);其中,该函数对象的N个参数放在 函数主体参数body的前面,即函数主 ...

  10. Windows 8.1 新控件和功能:

    http://msdn.microsoft.com/zh-cn/library/windows/apps/bg182878.aspx#five 将 XAML 树呈现为位图: 适用于 Windows 8 ...