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】题目难度提升的更多相关文章

  1. 【uoj#280】[UTR #2]题目难度提升 对顶堆+STL-set

    题目描述 给出 $n$ 个数 $a_1,a_2,...,a_n$ ,将其排为序列 $\{p_i\}$ ,满足 $\{前\ i\ 个数的中位数\}$ 单调不降.求字典序最大的 $\{p_i\}$ . 其 ...

  2. 【UTR #2】[UOJ#278]题目排列顺序 [UOJ#279]题目交流通道 [UOJ#280]题目难度提升

    [UOJ#278][UTR #2]题目排列顺序 试题描述 “又要出题了.” 宇宙出题中心主任 —— 吉米多出题斯基,坐在办公桌前策划即将到来的 UOI. 这场比赛有 n 道题,吉米多出题斯基需要决定这 ...

  3. uoj#280. 【UTR #2】题目难度提升(构造)

    传送门 咱先膜一下\(GXZ\)再说 我们先把序列从小到大排序,然后分情况讨论 无解是不存在的,从小到大输出所有数肯定可行 情况一,如果\(a[mid]=a[mid+1]\),因为最终的中位数也是它们 ...

  4. uoj280 【UTR #2】题目难度提升 堆维护中位数+set

    题目传送门 http://uoj.ac/problem/280 题解 这道题很妙啊. 这种题目如果给予选手足够的时间,每一个选手应该都能做出来. 大概就是核心思路看上去很简单,但是想要推出来并不简单. ...

  5. HDU 3076 ssworld VS DDD 概率dp,无穷级数,oj错误题目 难度:2

    http://acm.hdu.edu.cn/showproblem.php?pid=3076 不可思议的题目,总之血量越少胜率越高,所以读取时把两人的血量交换一下 明显每一轮的胜率和负率都是固定的,所 ...

  6. UVa 11627 - Slalom 二分. oj错误题目 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  7. UOJ Test Round #2

    昨天晚上打的这个比赛,简直一颗赛艇啊-- 感觉发挥的并不好.比赛的时候比较紧张,最后一题还脑残写了个离散化结果爆零了,哎我怎么这么逗逼-- 讲讲比赛经过吧. 比赛之前逗逼地以为是8:00开始,然后淡定 ...

  8. Noip模拟62 2021.9.26

    T1 Set 真就随机化拿了$90$?? 不过还是有依据的,毕竟这道题出解的几率很大,随出答案的概率也极大 所以不妨打一个随机化 1 #include<bits/stdc++.h> 2 # ...

  9. 关于托福改革后的难度、评分和拼分,听听ETS的老师怎么说

    “笔者有幸于几天前去到ETS位于普林斯顿的总部学习,聆听了他们关于托福考试的发展和变革的说明,在这里向大家汇报一下此行的收获.” 当从车上下来那一刻起,我们便被那辽阔的绿草地和宜人的风景所吸引,伴随着 ...

随机推荐

  1. 实例学习SSIS(三)--使用包配置

    原文:实例学习SSIS(三)--使用包配置 导读: 实例学习SSIS(一)--制作一个简单的ETL包 实例学习SSIS(二)--使用迭代 实例学习SSIS(三)--使用包配置 实例学习SSIS(四)- ...

  2. POJ Big Christmas Tree(最短的基础)

    Big Christmas Tree 题目分析: 叫你构造一颗圣诞树,使得 (sum of weights of all descendant nodes) × (unit price of the ...

  3. javascript 类型检测

    javascript数据类型分为简单数据类型和复杂数据类型.简单数据类型分为string,number,boolean,defined,null,复杂数据类型为Object.类型检测在写代码可能会非常 ...

  4. Effective C++(16) 成对使用new和delete时要采取相同的形式

      问题聚焦:     我们都知道,new和delete要成对使用,但是有时候,事情往往不是按我们预期的那样发展.     对于单一对象和对象数组,我们要分开考虑     遇到typedef时,也需要 ...

  5. 笔试总结篇(一) : 广州X公司笔试

    一.单选题: Ps : 当时由于去广州路上颠簸很困,导致刚做几分钟题目就睡了一觉.起来发现20分钟过去了.擦擦! 1. 假设磁盘文件foobar.txt 由 6个ASCII 码字符“foobar” 组 ...

  6. 【学习笔记】锋利的jQuery(四)AJAX

    一.load()方法 /* *如果没有参数传递,采用GET方式传递 *如果有参数,则自动转换成POST方式传递 *无论Ajax是否请求成功,请求完成后回调函数触发 */ load("test ...

  7. JqGrid帮助文档

    JQGrid是一个在jquery基础上做的一个表格控件,以ajax的方式和服务器端通信. JQGrid Demo 是一个在线的演示项目.在这里,可以知道jqgrid可以做什么事情. 下面是转自其他人b ...

  8. C++构造 下一个排列 的函数

    今天围观刘汝佳神犇的白书发现了一个好用的函数: next_permutation(); 可以用于可重, 或者不可重集, 寻找下一个排列. 时间复杂度尚不明. //适用于不可重和可重集的排列. # in ...

  9. Competitive

  10. Code First 启用迁移时出错 "No context type was found in the assembly"

    问题:Code First 启用迁移时找不到上下文DbContext所在的项目. PM> Enable-Migrations No context type was found in the a ...