Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) E 贪心
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 贪心的更多相关文章
- 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条路目前开启(即能走),剩下的都是关闭状态 定义: ...
- 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 ...
- 【枚举】【二分】Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D. Resource Distribution
题意:有两个服务要求被满足,服务S1要求x1数量的资源,S2要求x2数量的资源.有n个服务器来提供资源,第i台能提供a[i]的资源.当你选择一定数量的服务器来为某个服务提供资源后,资源需求会等量地分担 ...
- 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 ...
- 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 由变化规则可得: ...
- Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1) C.Producing Snow
题目链接 题意 每天有体积为Vi的一堆雪,所有存在的雪每天都会融化Ti体积,求出每天具体融化的雪的体积数. 分析 对于第i天的雪堆,不妨假设其从一开始就存在,那么它的初始体积就为V[i]+T[1. ...
- 【推导】【贪心】Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2) D. Riverside Curio
题意:海平面每天高度会变化,一个人会在每天海平面的位置刻下一道痕迹(如果当前位置没有已经刻划过的痕迹),并且记录下当天比海平面高的痕迹有多少条,记为a[i].让你最小化每天比海平面低的痕迹条数之和. ...
- 【推导】Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2) B. Mystical Mosaic
题意:给你一个棋盘的最终局面. 你的一次操作可以选择一些行和列,将它们的交叉点染黑,不能重复选择某行或者某列.问你是否能经过数次操作之后,达到目标局面. 就枚举所有黑点,如果该点行列都没被标记,就给它 ...
- 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 ...
随机推荐
- [摘抄]从 GitHub 身上学到的 3 个创业经验
1.找一个大问题去解决 让 Git 更容易使用是 GitHub 的目标,但它从来不是 GitHub 的最终目标.GitHub 的真正目标是让协作和编写软件变得更容易.世界上每一个软件开发者都在努力解决 ...
- idea使用actiBPM插件中文乱码
idea 安转activiti插件后,编辑流程图发现保存后中文乱码,并且idea的字符集(Settings—>Editor—>File Encodings)已经设置为UTF-8,流程图中中 ...
- IOTA price analysis
Iota coinchart Look at the trendline drawn in red color, at the very first beginning of this month, ...
- PHP学习 流程控制和数组
flow control 流程控制decision structure 判断结构loop structure 循环结构 if(condition){statement1;} if(){}else{} ...
- hive insert 动态分区异常(Error encountered near token)与解决
当insert数据到有分区的hive表里时若不明显指定分区会抛出异常 insert overwrite table persons_tmp select * from persons; FAILED: ...
- BugPhobia准备篇章:Scrum Meeting工作分析篇
特别说明:此博客不计入正式开发过程的Scrum Meeting篇章,只是工作的基础分析 前端 王鹿鸣.钱林琛撰写初稿 能否前端完成一个页面后就能在本地跑起来进行测试? 能否在前端和后端完成对接后单页面 ...
- SQL Sever——远程过程调用失败(0x800706be)
最近重装了系统,VS和SQL Sever莫名奇妙的不能用了.下面总结一下这个过程中遇到的问题,跟大家分享一下经验~~ 大概是以前的安装过程都十分顺利,这次,在尝试了数次登陆不上去之后,我仍然怀疑是自己 ...
- Answer My Questions
回答自己的问题,真棒!断电让自己的工作重来.真棒! 阅读以前自己的博客,发现问题都已经有了答案. (1).想要成为一名专业的软件工程师,首先得是有相关的资格证书,这个可以通过软考获得.然后在职场中锻炼 ...
- 安装VS2013
安装VS2013, 之前就有VS2010,安装了一个多小时,纠结,下面是截图. 1.安装 2.登录,之前就有账号了 3.这就是VS2013了. 4.测试 5通 ...
- Alpha冲刺测试
项目Alpha冲刺(团队) Alpha冲刺测试 姓名 学号 博客链接 何守成 031602408 http://www.cnblogs.com/heshoucheng/ 黄锦峰 031602411 h ...