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. 谈谈我对Manacher算法的理解

    Manacher算法其实是求字符串里面最长的回文. ①在学习该算法前,我们应该知道回文的定义:顺序读取回文和逆序读取回文得到的结果是一样的,如:abba,aba. 那么我们不难想到,在判断一个字符串s ...

  2. Daily Scrumming* 2015.12.11(Day 3)

    一.团队scrum meeting照片 二.今日总结 姓名 WorkItem ID 工作内容 签入链接以及备注说明  江昊 任务945 学习使用sass,学习的主要难点在于ruby环境的搭建.sass ...

  3. centos 64位 下hadoop-2.7.2 下编译

    centos 64位 下hadoop-2.7.2 下编译 由于机器安装的是centos 6.7 64位 系统  从hadoop中下载是32位  hadoop 依赖的的库是libhadoop.so 是3 ...

  4. beta1

    组长:吴晓晖 过去两天完成了哪些任务: 代码重构进行中,界面,预计两个beta单位完成 展示GitHub当日代码/文档签入记录 接下来的计划 更加人性化的推荐算法 还剩下哪些任务 有哪些困难 有哪些收 ...

  5. servlet编码乱码问题

    继承HttpServlet 重写doGet(HttpServletRequest req,HttpServletResponse resp),doPost()方法 post提交时: protected ...

  6. JS基础(三)语句

    一.判断语句(PS:一般情况下判断条件最终应该是一个布尔值.) 1.if语句 1)基本格式 if(判断条件){ 如果判断条件成立则执行的语句 }else{ 如果判断条件不成立则执行的语句 } 2)扩展 ...

  7. 第十周PSP&进度条

    PSP 一.表格: D日期     C类型 C内容 S开始时间 E结束时间 I时间间隔 T净时间(mins) 预计花费时间(mins) 11月17号 站立会议 分配任务 13:00 13:30 0 3 ...

  8. 【Leetcode】535. Encode and Decode TinyURL

    Question: TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/pro ...

  9. Python爬虫:抓取新浪新闻数据

    案例一 抓取对象: 新浪国内新闻(http://news.sina.com.cn/china/),该列表中的标题名称.时间.链接. 完整代码: from bs4 import BeautifulSou ...

  10. OneZero第四周第二次站立会议(2016.4.12)

    1. 时间: 13:00--13:10  共计10分钟. 2. 成员: X 夏一鸣 * 组长 (博客:http://www.cnblogs.com/xiaym896/), G 郭又铭 (博客:http ...