【UOJ #280】【UTR #2】题目难度提升
http://uoj.ac/problem/280
非常难想的贪心,用set\(O(nlogn)\)。
调了一天qwq。
题解

#include<set>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 100003;
multiset <int> S;
multiset <int> ans;
multiset <int> :: iterator L;
multiset <int> :: iterator R;
int a[N], n, hh, m;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", a + i); a[i] <<= 1;
S.insert(a[i]);
}
stable_sort(a + 1, a + n + 1);
int tmp;
for (tmp = (n + 1) / 2; tmp >= 1; --tmp)
if (a[tmp] == a[tmp + 1])
break;
set <int> :: iterator h;
if (tmp == 0) {
S.erase(a[1]); ans.insert(a[1]); m = a[1];
printf("%d ", a[1] >> 1);
for (int i = 2; i <= n; ++i) {
L = S.begin();
h = ans.upper_bound(m);
if (h != ans.end() && (*h < *L || *h <= 2 * (*L) - m)) L = --S.end();
else L = --S.upper_bound(2 * (*L) - m);
printf("%d ", *L >> 1);
ans.insert(*L);
if (!ans.count(m)) {
if (*L > m) m = *ans.upper_bound(m);
else m = *ans.lower_bound(m) - 1;
} else if (*L != m) {
if (*L > m) hh = *ans.upper_bound(m);
else hh = *--ans.lower_bound(m);
m = (1ll + m + hh) / 2;
}
S.erase(*L);
}
} else {
m = a[tmp];
S.erase(S.find(m)); S.erase(S.find(m));
ans.insert(m); ans.insert(m);
printf("%d %d ", m >> 1, m >> 1);
tmp = 2; bool flag = false;
while (S.size() > 1) {
L = --S.end();;
if (*L < m) {flag = true; break;}
ans.insert(*L); printf("%d ", *L >> 1);
S.erase(L);
L = S.upper_bound(m);
++tmp;
if (L == S.begin()) break;
--L;
ans.insert(*L); printf("%d ", *L >> 1);
S.erase(L);
++tmp;
}
if (flag) {
while (S.size()) {
L = --S.end();;
printf("%d ", *L >> 1);
S.erase(L);
}
return 0;
}
tmp = n - tmp;
for (int i = 1; i <= tmp; ++i) {
L = S.begin();
h = ans.upper_bound(m);
if (h != ans.end() && (*h < *L || *h <= 2 * (*L) - m)) L = --S.end();
else L = --S.upper_bound(2 * (*L) - m);
printf("%d ", *L >> 1);
ans.insert(*L);
if (!ans.count(m)) {
if (*L > m) m = *ans.upper_bound(m);
else m = *ans.lower_bound(m) - 1;
} else if (*L != m) {
if (*L > m) hh = *ans.upper_bound(m);
else hh = *--ans.lower_bound(m);
m = (1ll + m + hh) / 2;
}
S.erase(L);
}
}
return 0;
}
【UOJ #280】【UTR #2】题目难度提升的更多相关文章
- 【uoj#280】[UTR #2]题目难度提升 对顶堆+STL-set
题目描述 给出 $n$ 个数 $a_1,a_2,...,a_n$ ,将其排为序列 $\{p_i\}$ ,满足 $\{前\ i\ 个数的中位数\}$ 单调不降.求字典序最大的 $\{p_i\}$ . 其 ...
- 【UTR #2】[UOJ#278]题目排列顺序 [UOJ#279]题目交流通道 [UOJ#280]题目难度提升
[UOJ#278][UTR #2]题目排列顺序 试题描述 “又要出题了.” 宇宙出题中心主任 —— 吉米多出题斯基,坐在办公桌前策划即将到来的 UOI. 这场比赛有 n 道题,吉米多出题斯基需要决定这 ...
- uoj#280. 【UTR #2】题目难度提升(构造)
传送门 咱先膜一下\(GXZ\)再说 我们先把序列从小到大排序,然后分情况讨论 无解是不存在的,从小到大输出所有数肯定可行 情况一,如果\(a[mid]=a[mid+1]\),因为最终的中位数也是它们 ...
- uoj280 【UTR #2】题目难度提升 堆维护中位数+set
题目传送门 http://uoj.ac/problem/280 题解 这道题很妙啊. 这种题目如果给予选手足够的时间,每一个选手应该都能做出来. 大概就是核心思路看上去很简单,但是想要推出来并不简单. ...
- HDU 3076 ssworld VS DDD 概率dp,无穷级数,oj错误题目 难度:2
http://acm.hdu.edu.cn/showproblem.php?pid=3076 不可思议的题目,总之血量越少胜率越高,所以读取时把两人的血量交换一下 明显每一轮的胜率和负率都是固定的,所 ...
- UVa 11627 - Slalom 二分. oj错误题目 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UOJ Test Round #2
昨天晚上打的这个比赛,简直一颗赛艇啊-- 感觉发挥的并不好.比赛的时候比较紧张,最后一题还脑残写了个离散化结果爆零了,哎我怎么这么逗逼-- 讲讲比赛经过吧. 比赛之前逗逼地以为是8:00开始,然后淡定 ...
- Noip模拟62 2021.9.26
T1 Set 真就随机化拿了$90$?? 不过还是有依据的,毕竟这道题出解的几率很大,随出答案的概率也极大 所以不妨打一个随机化 1 #include<bits/stdc++.h> 2 # ...
- 关于托福改革后的难度、评分和拼分,听听ETS的老师怎么说
“笔者有幸于几天前去到ETS位于普林斯顿的总部学习,聆听了他们关于托福考试的发展和变革的说明,在这里向大家汇报一下此行的收获.” 当从车上下来那一刻起,我们便被那辽阔的绿草地和宜人的风景所吸引,伴随着 ...
随机推荐
- 【c++类的构造函数具体解释
】
一.构造函数是干什么的 class Dog { public: // 类Dog的构造函数 // 特点:以类名作为函数名,无返回类型 Dog() ...
- ajax的get请求
get和post是http请求方法最主要的两种方式. get: 先实现一个简单的get请求 index.html <!DOCTYPE html> <html lang="e ...
- c# 即使服务又是可执行程序的代码实现
先看下代码 namespace UpdaterServer { class Program { static void Main(string[] args) { ) { ServiceBase[] ...
- ASP.NET交互Rest服务接口(Jquery的Get与Post方式)
ASP.NET交互Rest服务接口(Jquery的Get与Post方式) 本文将通过一个简单的实例,介绍如何创建一个Rest服务接口,以及通过JQUERY去对它进行调用;主要采取两种方式分别为Get跟 ...
- [转]OPENSOLARIS 2009.06 REPOSITORY ISO IMAGES NOW AVAILABLE
Source: http://hosam.wordpress.com/2009/07/25/opensolaris-2009-06-repository-iso-images-now-availabl ...
- geek 的博客
hexo 适合前端 geek 的博客 原文出自:http://www.qiangji.tk/hexo%E9%80%82%E5%90%88%E5%89%8D%E7%AB%AFgeek%E7%9A%8 ...
- nc 简单的使用
非常强大的网络工具nc netcat 下面自己总结了它的几种常用用法(参考了它的man): 1.聊天 ClientA: nc - ClientB: nc A'sIP 1234 2.数据传输 Clien ...
- eclipse在Ubuntu 13.04下的安装过程
eclipse在Ubuntu 13.04下的安装过程及问题小记 一.eclipse安装过程 首先确保在安装eclipse之前已经安装好Java虚拟机 1. eclipse官网下载压缩包 下载地址:ht ...
- 核心C#
核心C# 内容提要: 声明变量:变量的初始化和作用域:C#的预定义数据类型:在C#程序中使用条件语句.循环和跳转语句指定执行流:枚举:名称空间: Main()方法:基本命令行C#编译器选项:使用Sys ...
- JS自动刷新页面一次
<script type="text/javascript"> //刷新页面 if(location.href.indexOf("refresh=1" ...