Codeforces 1131 C. Birthday-暴力 (Codeforces Round #541 (Div. 2))
1 second
256 megabytes
standard input
standard output
Cowboy Vlad has a birthday today! There are nn children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible.
Formally, let's number children from 11 to nn in a circle order, that is, for every ii child with number ii will stand next to the child with number i+1i+1, also the child with number 11 stands next to the child with number nn. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other.
Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible.
The first line contains a single integer nn (2≤n≤1002≤n≤100) — the number of the children who came to the cowboy Vlad's birthday.
The second line contains integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) denoting heights of every child.
Print exactly nn integers — heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child.
If there are multiple possible answers, print any of them.
- 5
- 2 1 1 3 2
- 1 2 3 2 1
- 3
- 30 10 20
- 10 20 30
In the first example, the discomfort of the circle is equal to 11, since the corresponding absolute differences are 11, 11, 11 and 00. Note, that sequences [2,3,2,1,1][2,3,2,1,1] and [3,2,1,1,2][3,2,1,1,2] form the same circles and differ only by the selection of the starting point.
In the second example, the discomfort of the circle is equal to 2020, since the absolute difference of 1010 and 3030 is equal to 2020.
题意就是构造序列,要求成一个环然后相邻两个差值尽量小。
代码:
- //C
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const int maxn=1e3+;
- int a[maxn],b[maxn];
- int main()
- {
- int n;
- cin>>n;
- for(int i=;i<=n;i++)
- cin>>a[i];
- sort(a+,a++n);
- int l=,r=n;
- for(int i=;i<=n;i++){
- if(i%==) b[l++]=a[i];
- else b[r--]=a[i];
- }
- for(int i=;i<=n;i++)
- cout<<b[i]<<" ";
- cout<<endl;
- }
Codeforces 1131 C. Birthday-暴力 (Codeforces Round #541 (Div. 2))的更多相关文章
- Codeforces 1131 B. Draw!-暴力 (Codeforces Round #541 (Div. 2))
B. Draw! time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- Codeforces Round #541 (Div. 2)
Codeforces Round #541 (Div. 2) http://codeforces.com/contest/1131 A #include<bits/stdc++.h> us ...
- Codeforces Round #541 (Div. 2) (A~F)
目录 Codeforces 1131 A.Sea Battle B.Draw! C.Birthday D.Gourmet choice(拓扑排序) E.String Multiplication(思路 ...
- Codeforces 1131 F. Asya And Kittens-双向链表(模拟或者STL list)+并查集(或者STL list的splice()函数)-对不起,我太菜了。。。 (Codeforces Round #541 (Div. 2))
F. Asya And Kittens time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 1131 A. Sea Battle-暴力 (Codeforces Round #541 (Div. 2))
A. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #541 (Div. 2)题解
不知道该更些什么 随便写点东西吧 https://codeforces.com/contest/1131 ABC 太热了不写了 D 把相等的用并查集缩在一起 如果$ x<y$则从$ x$往$y$ ...
- Codeforces Round #541 (Div. 2) D(并查集+拓扑排序) F (并查集)
D. Gourmet choice 链接:http://codeforces.com/contest/1131/problem/D 思路: = 的情况我们用并查集把他们扔到一个集合,然后根据 > ...
- Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...
- Codeforces Round #541 (Div. 2) E 字符串 + 思维 + 猜性质
https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1 ...
随机推荐
- Windows常用shell命令大全(转)
[Windows常用shell命令大全] 基于鼠标操作的后果就是OS界面外观发生改变, 就得多花学习成本.更主要的是基于界面引导Path与命令行直达速度是难以比拟的.另外Geek很大一部分是键盘控,而 ...
- How to solve “Device eth0 does not seem to be present, delaying initialization” error
Today, I encountered with a strange error after I cloned CentOS 6 guest machine in Oracle VirtualBox ...
- iOS 网络请求--- AFNetworing的使用
一.GET请求方式: //1.管理器 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; ...
- Html5学习3(拖放、Video(视频)、Input类型(color、datetime、email、month 、number 、range 、search、Tel、time、url、week ))
1.Html拖放 <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> < ...
- UIImageView属性---iOS-Apple苹果官方文档翻译
本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址 //转载请注明出处--本文永久链接:http://www.cnblogs.com/C ...
- webpack 4 :从0配置到项目搭建
webpack4发布以来,我写项目都是用脚手架,即使再简单的项目,真的是really shame..虽然道听途说了很多 webpack4 的特性,却没有尝试过,因为它给人的感觉就是,em...很难.但 ...
- Gulp、Grunt构建工具
在Gulp中创建一个库从磁盘gulp.src读取源文件并通过磁盘管道写回内容到gulp.dest,可以理解成只是将文件复制到另一个目录. var gulp = require('gulp'); gul ...
- servlet线程不安全
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlgAAAE9CAIAAABY1Yv/AAAgAElEQVR4nOy9eVxN2/8/viuaU5kqZW
- mysql 复制表结构 / 从结果中导入数据到新表
这只会复制结构: mysql> create table a like mysql1; Query OK, 0 rows affected (0.03 sec) mysql> desc a ...
- HDU 5117 Fluorescent
题目链接:HDU-5117 题意为有n盏灯,m个开关,每个开关控制着\( k_{i} \)灯.X为最后亮着的灯的个数,要求出\( E(X^{3} ) * 2^{M} mod (10^9 + 7) \) ...