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. MY WAY程序(十八) 团队开发

    1.通信知识          要了解的强哥的移动通信先验知识布局.我和另外一个毕业生有自己的学习,但我真的没有认真看.了解了一下,其余大部分时间在搞nodejs.另外一个应届毕业生则是按着一本电子书 ...

  2. 编辑控件CKEditor和CKFinder

    -使用HTML编辑控件CKEditor和CKFinder Web开发上有很多HTML的编辑控件,如CKEditor.kindeditor等等,很多都做的很好,本文主要介绍在MVC界面里面,CKEdit ...

  3. EntityFramework中支持BulkInsert扩展

    EntityFramework中支持BulkInsert扩展 本文为 Dennis Gao 原创技术文章,发表于博客园博客,未经作者本人允许禁止任何形式的转载. 前言 很显然,你应该不至于使用 Ent ...

  4. html+js+ashx+easyui+ado.net权限管理系统

    分享一个html+js+ashx+easyui+ado.net权限管理系统   EasyUI.权限管理 这是个都快被搞烂了的组合,但是easyui的确好用,权限管理在项目中的确实用.一直以来博客园里也 ...

  5. The Decoder - UVa458

    欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/uva458.html 题目描述  The ...

  6. JAVA 作业:图形界面

    自己动手写的一个小JAVA 程序: 一个学生管理小系统,虽然很挫,但是这我学JAVA的第一步.学了2天JAVA没有白费! import java.awt.*; import java.awt.even ...

  7. Lex Yacc手册

    Python Lex Yacc手册 本文是PLY (Python Lex-Yacc)的中文翻译版.转载请注明出处.这里有更好的阅读体验. 如果你从事编译器或解析器的开发工作,你可能对lex和yacc不 ...

  8. MVC视图中的@Html.xxx(...)

    ASP.NET MVC视图中的@Html.xxx(...)   问题 在视图页中@Html.xxx(...)是什么?如何被执行? 如下图所示: 解疑 视图页中@Html.xxx(...)涉及的内容有: ...

  9. 捆绑(Bundle)

    捆绑(Bundle) 本文介绍 MVC 4 提供的一个新特性:捆绑(Bundle),一个在  View 和 Layout 中用于组织优化浏览器请求的 CSS 和 JavaScript 文件的技术. 本 ...

  10. asp.net 加入验证码

    验证码生成页面代码(清理掉没用的html) using System; using System.Collections.Generic; using System.Linq; using Syste ...