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则没有,最后给你起点和终点,问你要是 ...
随机推荐
- 【zTree】zTree的3.5.26静态树与动态树(实用)
1.静态树: 目录结构:(css与js为下载的原文件夹)
- linux ip白名单、防火墙白名单 设置
http://blog.csdn.net/catoop/article/details/50476099 登录信息在 /var/log/secure linux ip白名单 配置文件:/etc/hos ...
- 2. 数据库文件配置与简单操作 Model / M()
官方文档说明位置: Thinkphp/Conf/convention.php 内容说明如下: 'DB_TYPE' => '', // 数据库类型 'DB_HOST' => '', // 服 ...
- Android设备相关配置
http://source.android.com/devices/tech/storage/index.html Android supports devices with external sto ...
- java基础11 继承(super、extends关键字和重写,这三个要素出现的前提:必须存在继承关系)
面向对象的三大特征: 1.封装 (将一类属性封装起来,并提供set()和get()方法给其他对象设置和获取值.或者是将一个运算方法封装起来,其他对象需要此种做运算时,给此对象调用) 2.继承 ...
- C++卷积神经网络实例(一)
跟着这位博主来学习C++的卷积网络实例,因为作者一直在更新代码,所以新的代码和这位博主的分析有所不同:这位博主写的东西太泛了,没有讲到实质, 可以参考下他分析的类与类之间的关系图.. 前四节:http ...
- Mysql锁的类型与简析
数据库锁设计的初衷是处理并发问题.作为多用户共享的资源,当出现并发访问的时候,数据库需要合理地控制资源的访问规则.而锁就是用来实现这些访问规则的重要数据结构. 根据加锁的范围,MySQL 里面的锁大致 ...
- Mysql Federated Server 示例
Federated存储引擎访问在远程数据库的表中的数据,而不是本地的表.创建一个Federated表的时候,服务器在数据库目录创建一个表定义文件.无其它表被创建,因为实际的数据在一个远程数据库上.这不 ...
- mybatis基础之二
UserMapper.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper ...
- SQL必知必会 -------- 聚集函数、分组排序
聚集函数 1.AVG()函数 输入:SELECT AVG(prod_price) AS avg_price FROM Products 输出: 警告:只用于单个列AVG()只能用来确定特定数值列的平均 ...