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则没有,最后给你起点和终点,问你要是 ...
随机推荐
- vista风格的cms企业html后台管理系统模板——后台
链接:http://pan.baidu.com/s/1c1Cv99e 密码:20yz
- NFS挂载报如下错误信息:mount.nfs: Stale NFS file handle解决
1)用fuser杀掉占用那个目录的进程 linux:~ # fuser -k /home/msgplus/msgplus/remote_dir 2)强制umount linux:~ # umount ...
- shell中的变量与eval(转)
原文链接:http://www.361way.com/shell-eval-variable/4957.html shell 中经常会用到变量的嵌套的情况.比如,单个或多个变量的值作为变量名,再对该变 ...
- wxPython 画图板
终于开始Python学习之旅了,姑且以一个“画图板”小项目开始吧.放慢脚步,一点一点地学习. 1月28日更新 第一次遇到的麻烦便是“重绘”,查了好多资料,终于重绘成功了. #-*- encoding: ...
- 【Mac】appium的环境搭建
1.下载appium并安装,进入官网下载即可 http://appium.io 2.下载安装pip,因为pip执行命令的安装,会出现某些包的下载失败,因此使用brew进行 https://pypi.o ...
- [你必须知道的.NET]第二十一回:认识全面的null
发布日期:2008.7.31 作者:Anytao © 2008 Anytao.com ,Anytao原创作品,转贴请注明作者和出处. 说在,开篇之前 null.nullable.??运算符.null ...
- 邂逅Sass和Compass之Compass篇
本文主要讲解Compass的内容,众所周知Compass是Sass的工具库,如果对Sass不甚了解的同学可以移步 邂逅Sass和Compass之Sass篇 Sass本身只是一个“CSS预处理器”,Co ...
- Ubuntu16.4 修改静态ip地址
root@temple-102:~# ifconfig eno1 Link encap:Ethernet HWaddr 0c:c4:7a:e6:49:74 UP BROADCAST MULTICAST ...
- 找到最大或最小的N个元素---heapq模块
堆排序heapq的用法 基本用法: 复杂数据结构: # coding=utf- # example.py # Example of using heapq to find the N smallest ...
- gcc编译器参数
[gcc编译步骤] 1.预处理,生成.i的文件[预处理器cpp] 2.将预处理后的文件转换成汇编语言,生成文件.s[编译器egcs] 3.由汇编变为目标代码(机器代码)生成.o的文件[汇编器as] 4 ...