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. 从头到尾谈一下HTTPS

    引言 “你能谈一下HTTPS吗?” “一种比HTTP安全的协议.” “...” 如果面试这样说的话那差不多就gg了,其实HTTPS要展开回答的话内容还挺丰富的.本篇文章详细介绍了HTTPS是什么.为什 ...

  2. python基础篇----基本数据类型

    bit  #bit_length 当前数字的二进制,只用用n位来表示a = 123b = a.bit_length()print(b)#==>7

  3. camscanner(扫描全能王)功能解析与复现

    早就在用camscanner(扫描全能王)这个软件,感觉很不错. 主要功能: 1.页面截取校正 2.增强处理(灰度与颜色) 刚好最近工作与此相关,静心做点仿真,看看其中的操作原理,也做个demo玩玩. ...

  4. Kaggle入门(一)——Digit Recognizer

    目录 0 前言 1 简介 2 数据准备 2.1 导入数据 2.2 检查空值 2.3 正则化 Normalization 2.4 更改数据维度 Reshape 2.5 标签编码 2.6 分割交叉验证集 ...

  5. PAT甲题题解-1077. Kuchiguse (20)-找相同后缀

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

  6. Daily Scrumming* 2015.12.13(Day 5)

    一.团队scrum meeting照片 二.今日总结 姓名 WorkItem ID 工作内容 签入链接以及备注说明  江昊 任务1063 查找与学习前端工具库,并写出一篇指导文档 https://gi ...

  7. 《Linux内核设计与实现》第一、二章学习笔记

    <Linux内核设计与实现>第一.二章学习笔记 姓名:王玮怡  学号:20135116 第一章 Linux内核简介 一.关于Unix ——一个支持抢占式多任务.多线程.虚拟内存.换页.动态 ...

  8. SE Springer小组《Spring音乐播放器》软件需求说明之四

    4 运行环境规定 4.1设备 我们计划完成的音乐软件较小巧,功能并不复杂,在普通笔记本电脑中即可运行,并无特殊硬设备要求. 4.2支持软件 需要用到windows操作系统,用VS编写C/C++代码,还 ...

  9. 基于 Laravel 的 文件管理

    以 laravel 5.5 为例,框架集成了文件系统和云存储功能 可以实现文件夹列表.创建.重命名.删除,文件列表.上传.重命名.删除等操作 一.先进行配置 在 config 文件夹下有 filesy ...

  10. 微信 小程序组件 加入购物车全套 one wxml

    <!--pages/shop/shop.wxml--> <view wx:if="{{hasList}}"> <view class="co ...