http://codeforces.com/contest/967/problem/E

题目大意:

给你一个数组a,a的长度为n

定义:b(i) = a(1)^a(2)^......^a(i),

问,是否存在一种情况,使得a(i)重新排列以后以后,满足b(i)是严格单调递增的。

思路:

对于二进制位操作来说,如果异或后值增加,即 p^q > p,必然满足两种情况(假定一个为p,一个为q)

①q的最高位>p的最高位

②q的最高位(假定第k为最高) < p的最高位,但是p的第k位为0

这样,我们就贪心的去找就好啦。

每次都贪心的找符合条件的,且value最小的即可。

//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker,"/STACK:102400000,102400000")
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha printf("haha\n")
const int maxn = 1e5 + ;
int n;
vector<LL> ve;
vector<LL> bite;
vector<LL> G[maxn];
int pos[maxn];
int maxlen; void get_bite(LL sum){
bite.clear();
while (sum){
bite.pb(sum % );
sum >>= ;
}
} bool solve(){
LL sum = ;
vector<LL> ans;
for (int i = ; i <= n; i++){
get_bite(sum);
bool flag = false;
for (int j = ; j <= maxlen; j++){
if (j == bite.size()) continue;
else if (j < bite.size() && (bite[j - ] == )){
if (G[j].size() > && (G[j].size() > pos[j])){
flag = true;
ans.push_back(G[j][pos[j]]);
sum ^= G[j][pos[j]];
pos[j]++;
break;
}
}
else if (j > bite.size()){
if (G[j].size() > && (G[j].size() > pos[j])){
flag = true;
ans.push_back(G[j][pos[j]]);
sum ^= G[j][pos[j]];
pos[j]++;
break;
}
}
}
if (!flag) return false;
}
puts("Yes");
for (int i = ; i < ans.size(); i++){
printf("%lld ", ans[i]);
}
cout << endl;
return true;
} int main(){
cin >> n;
for (int i = ; i <= n; i++){
LL a; scanf("%lld", &a);
ve.pb(a);
}
for (int i = ; i < ve.size(); i++){
LL tmp = ve[i];
int cnt = ;
while (tmp){
cnt++;
tmp >>= ;
}
G[cnt].pb(ve[i]);
maxlen = max(maxlen, cnt);
}
for (int i = ; i <= maxlen; i++){
sort(ALL(G[i]));
}
if (solve() == false) puts("No");
return ;
}

Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) E 贪心的更多相关文章

  1. Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) F 构造

    http://codeforces.com/contest/967/problem/F 题目大意: 有n个点,n*(n-1)/2条边的无向图,其中有m条路目前开启(即能走),剩下的都是关闭状态 定义: ...

  2. Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D 贪心

    http://codeforces.com/contest/967/problem/D 题目大意: 有n个服务器,标号为1~n,每个服务器有C[i]个资源.现在,有两个任务需要同时进行,令他为x1,x ...

  3. 【枚举】【二分】Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D. Resource Distribution

    题意:有两个服务要求被满足,服务S1要求x1数量的资源,S2要求x2数量的资源.有n个服务器来提供资源,第i台能提供a[i]的资源.当你选择一定数量的服务器来为某个服务提供资源后,资源需求会等量地分担 ...

  4. Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)A. Protect Sheep

    http://codeforces.com/contest/948/problem/A   A. Protect Sheep Bob is a farmer. He has a large pastu ...

  5. Codeforces Round #470 (rated, Div. 1, based on VK Cup 2018 Round 1) 923D 947D 948E D. Picking Strings

    题: OvO http://codeforces.com/contest/947/problem/D 923D 947D 948E 解: 记要改变的串为 P1 ,记目标串为 P2  由变化规则可得: ...

  6. Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1) C.Producing Snow

    题目链接  题意  每天有体积为Vi的一堆雪,所有存在的雪每天都会融化Ti体积,求出每天具体融化的雪的体积数. 分析 对于第i天的雪堆,不妨假设其从一开始就存在,那么它的初始体积就为V[i]+T[1. ...

  7. 【推导】【贪心】Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2) D. Riverside Curio

    题意:海平面每天高度会变化,一个人会在每天海平面的位置刻下一道痕迹(如果当前位置没有已经刻划过的痕迹),并且记录下当天比海平面高的痕迹有多少条,记为a[i].让你最小化每天比海平面低的痕迹条数之和. ...

  8. 【推导】Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2) B. Mystical Mosaic

    题意:给你一个棋盘的最终局面. 你的一次操作可以选择一些行和列,将它们的交叉点染黑,不能重复选择某行或者某列.问你是否能经过数次操作之后,达到目标局面. 就枚举所有黑点,如果该点行列都没被标记,就给它 ...

  9. Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)

    A. Protect Sheep time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

随机推荐

  1. centos7 部署LNMP

    1.安装Nginx 使用Nginx官方提供的rpm包 [root@nginx ~]# cat /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo b ...

  2. python中字符串的常见操作方法

    1. 字符串概念,字符串是一个容器,包含若干个字符并按照一定的顺序组织成一个整体.字符串支持索引操作. 2. 创建字符串基本语法 变量名 = "字符串信息" 变量名 = '字符串信 ...

  3. Python_Xlrd&Xlwt

    import xlrd # \U 开始的字符被编译器认为是八进制 解决方法 r objWB = xlrd.open_workbook(r'C:\Users\IBM\Desktop\S1\7月下旬入库表 ...

  4. 【转】Cocos2d-x 3.x基础学习: 总结数学类Vec2/Size/Rect

    转载:http://www.taikr.com/article/1847 在Cocos2d-x 3.x中,数学类Vec2.Size.Rect,是比较常用的类.比如设置图片位置,图片大小,两图片的碰撞检 ...

  5. 7. Reverse Integer【Leetcode by java】

    Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Examp ...

  6. [paper]MaskFusion: Real-Time Recognition, Tracking and Reconstruction of Multiple Moving Objects

    Before 近期在调研关于RGBD在室内移动机器人下的语义导航的研究.目前帝国理工的Andrew Davison在这边有两个团队在研究,分别是Fusion++ 和 这篇 MaskFusion.这篇是 ...

  7. [T-ARA][Tic Tic Toc]

    歌词来源:http://music.163.com/#/song?id=22704478 Tic Tic Toc RA Tic Tic Toc RA [Tic Tic Toc RA Tic Tic T ...

  8. 《在kali上完成gdb调试》

    kali使用流程 1.使menuos停止 方法如图: 效果如图: 2.启动调试 打开一个新的命令行,然后方法如下图: 3.设置断点 注:由图可看出,断点设置在sys_clone,dup_task_st ...

  9. 《Linux内核分析》 第三周 构造一个简单的Linux系统MenuOS

    Linux内核分析 第三周 构造一个简单的Linux系统MenuOS 张嘉琪 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/ ...

  10. jQuery~DOM基础操作

    操作DOM 1.什么是DOM:document object model文档对象模型 2.树形结构 3.什么是节点(node):DOM结构中最小单位,元素.文本.属性...创建节点 var $div ...