Educational Codeforces Round 10 B. z-sort 构造
B. z-sort
题目连接:
http://www.codeforces.com/contest/652/problem/B
Description
A student of z-school found a kind of sorting called z-sort. The array a with n elements are z-sorted if two conditions hold:
ai ≥ ai - 1 for all even i,
ai ≤ ai - 1 for all odd i > 1.
For example the arrays [1,2,1,2] and [1,1,1,1] are z-sorted while the array [1,2,3,4] isn’t z-sorted.
Can you make the array z-sorted?
Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array a.
The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a.
Output
If it's possible to make the array a z-sorted print n space separated integers ai — the elements after z-sort. Otherwise print the only word "Impossible".
Sample Input
4
1 2 2 1
Sample Output
1 2 1 2
Hint
题意
定义一个z排序,就是奇数位置满足ai<=a[i-1]
偶数位置满足ai>=a[i-1]
给你n个数,让你构造出来这个z排序的序列
无解输出impossible
题解:
一个小的一个大的就好了
我们先排序,然后奇数位置从1开始放,偶数位置从(n+1)/2+1开始放,这样子扔下去的奇数位置一定小于等于偶数位置。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3+5;
int n,a[maxn],b[maxn];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
sort(a+1,a+1+n);
int l=1,r=(n+1)/2+1;
for(int i=1;i<=n;i++)
{
if(i%2==1)printf("%d ",a[l++]);
else printf("%d ",a[r++]);
}
}
Educational Codeforces Round 10 B. z-sort 构造的更多相关文章
- Educational Codeforces Round 10
A:Gabriel and Caterpillar 题意:蜗牛爬树问题:值得一提的是在第n天如果恰好在天黑时爬到END,则恰好整除,不用再+1: day = (End - Begin - day0)/ ...
- Educational Codeforces Round 10 D. Nested Segments
D. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 10 A B题、
A. Gabriel and Caterpillar 题意: 就是说 一个小孩子去观察毛毛虫从 h1的地方爬到h2的地方.毛毛虫从10点爬到22点.每小时爬的距离是a, 晚上22点到第二天早上10点 ...
- Educational Codeforces Round 10 D. Nested Segments (树状数组)
题目链接:http://codeforces.com/problemset/problem/652/D 给你n个不同的区间,L或者R不会出现相同的数字,问你每一个区间包含多少个区间. 我是先把每个区间 ...
- CF Educational Codeforces Round 10 D. Nested Segments 离散化+树状数组
题目链接:http://codeforces.com/problemset/problem/652/D 大意:给若干个线段,保证线段端点不重合,问每个线段内部包含了多少个线段. 方法是对所有线段的端点 ...
- Educational Codeforces Round 10 D. Nested Segments 离线树状数组 离散化
D. Nested Segments 题目连接: http://www.codeforces.com/contest/652/problem/D Description You are given n ...
- Educational Codeforces Round 10 A. Gabriel and Caterpillar 模拟
A. Gabriel and Caterpillar 题目连接: http://www.codeforces.com/contest/652/problem/A Description The 9-t ...
- Educational Codeforces Round 10 D. Nested Segments 【树状数组区间更新 + 离散化 + stl】
任意门:http://codeforces.com/contest/652/problem/D D. Nested Segments time limit per test 2 seconds mem ...
- Educational Codeforces Round 10 E - Pursuit For Artifacts (强联通缩点 + 回溯)
题目链接:http://codeforces.com/contest/652/problem/E 给你n个点m个边,x和y双向连接,要是z是1表示这条边上有宝藏,0则没有,最后给你起点和终点,问你要是 ...
随机推荐
- 浅谈iOS多线程
浅谈iOS多线程 首先,先看看进程和线程的概念. 图1.1 这一块不难理解,重点点下他们的几个重要区别: 1,地址空间和资源:进程可以申请和拥有系统资源,线程不行.资源进程间相互独立,同一进程的各线程 ...
- Docker practice
Docker 实践 目标 创建一个基于最新版Ubuntu的镜像,在该镜像中更新apt包源并安装NTP package,最后将该新镜像提交到本地私有的registry中. 本地创建私有Registry ...
- Python 中的闭包与装饰器
闭包(closure)是函数式编程的重要的语法结构.闭包也是一种组织代码的结构,它同样提高了代码的可重复使用性. 如果在一个内嵌函数里,对在外部函数内(但不是在全局作用域)的变量进行引用,那么内嵌函数 ...
- Zabbix3.0源码安装
环境:nginx1.6.3 php-5.6.22 mysql-5.5.49 请参考前面的博文自行搭建 安装依赖并创建用户 [root@test88 ~]# yum install -y libxml2 ...
- 2017百度春招<不等式排列>
题目: 度度熊最近对全排列特别感兴趣,对于1到n的一个排列,度度熊发现可以在中间根据大小关系插入合适的大于和小于符号(即 '>' 和 '<' )使其成为一个合法的不等式数列.但是现在度度熊 ...
- U3D的一些常用基础脚本
修改渲染颜色和贴图 1: var texture :Texture ; 2: 3: function Start () { 4: renderer.material.mainTexture = te ...
- Linux下var目录介绍
var目录 /var 包括系统运行时要改变的数据.其中包括每个系统是特定的,即不能够与其他计算机共享的目录,如/var/log,/var/lock,/var/run.有些目录还是可以与其他系统共享,如 ...
- python【项目】:选课系统【简易版】
功能要求 角色:学校.学员.课程.讲师要求:1. 创建学校2. 创建课程3. 课程包含,周期,价格,通过学校创建课程4. 通过学校创建班级, 班级关联课程.讲师5. 创建学员时,选择学校,关联班级5. ...
- 深度学习方法(十):卷积神经网络结构变化——Maxout Networks,Network In Network,Global Average Pooling
欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.net/xbinworld. 技术交流QQ群:433250724,欢迎对算法.技术感兴趣的同学加入. 最近接下来几篇博文会回到神经网络结构 ...
- JavaScript(获取或设置html元素的宽,高,坐标),确定和判断鼠标是否在元素内部,二级导航菜单鼠标离开样式问题解决
设置: document.getElementById('id').style.width=value document.getElementById('id').style.height=va ...