Educational Codeforces Round 10 B. z-sort
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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".
Examples
Input
Copy
4
1 2 2 1
Output
Copy
1 2 1 2
Input
Copy
5
1 3 2 2 5
Output
Copy
1 5 2 3 2
题解:这道看起来像个排序题,第偶数个数要>=前一个数,第奇数个数要<=前一个数,
事实上这道题看样例会发现只要把源数列排序后前面一个,结尾一个依次输出就行,比如 13 2 2 5 ,排序后为 1 2 2 3 5,
输出第一个 1 ,输出最后一个5,输出第二个 2 ,输出倒数第二个 3,依次类推,即可.
#include <bits/stdc++.h>
const int N=1e3+5;
using namespace std;
int a[N];
int main(){int n;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&a[i]);}sort(a+1,a+n+1);//for(int i=1;i<=n;i++) printf("%d\n",a[i]);if(n%2==0){for(int i=1;i<=n/2;i++){printf("%d %d ",a[i],a[n-i+1]);}}else{for(int i=1;i<=n/2;i++){printf("%d %d ",a[i],a[n-i+1]);}printf("%d",a[n/2+1]);}return 0;}
转载于:https://www.cnblogs.com/-yjun/p/10424257.html
Educational Codeforces Round 10 B. z-sort相关推荐
- 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 C. Foe Pairs —— 后缀和
题目链接:http://codeforces.com/problemset/problem/652/C C. Foe Pairs time limit per test 1 second memory ...
- Educational Codeforces Round 10 C. Foe Pairs
C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Educational Codeforces Round 10 C. Foe Pairs 水题
C. Foe Pairs 题目连接: http://www.codeforces.com/contest/652/problem/C Description You are given a permu ...
- coderforce Educational Codeforces Round 10 C. Foe Pairs(贪心)
C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Educational Codeforces Round 17 E. Radio stations cdq分治 + 树状数组
传送门 文章目录 题意 思路: 题意 有nnn个电台,对于每个电台iii有三个参数xi,ri,fix_i,r_i,f_ixi,ri,fi,分别指他们的坐标.作用半径.频率.如果两个电台频率差值在 ...
- Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...
- Educational Codeforces Round 89 (Rated for Div. 2)(A, B, C, D)
Educational Codeforces Round 89 (Rated for Div. 2) A. Shovels and Swords 思路 题意非常简单,就是得到最多的物品嘛,我们假定a, ...
- Educational Codeforces Round 54 (Rated for Div.2)
Educational Codeforces Round 54 (Rated for Div.2) D. Edge Deletion 题意:一张n个点的无向图,保留其中k条边,使得有尽可能多的点与1的 ...
最新文章
- 通过joystick遥感和按键控制机器人--11
- 可用性高达99.999%!支付系统高可用架构设计实战
- HAN:基于双层注意力机制的异质图深度神经网络
- [HNOI2011]XOR和路径
- Java程序员---技能树
- [BZOJ2048] [2009国家集训队] 书堆
- 主动FTP vs. 被动FTP 权威解释
- 2021 年全国大学生电子设计竞赛实施过程说明
- linux自带perl加密,关于加密:如何在Perl脚本中加密或隐藏密码?
- 应用系统开发--银行系统
- dh算法 理论依据_DH算法
- 教程7--Schemas和客户端库
- Python 中文(大写)数字转阿拉伯数字
- 如何衡量软件系统的复杂度(二)
- 2022哈工大(深圳)计算机854考研经验贴|双非跨考|初试367 复试293
- Yolo学习(框架分析)
- PHP Imagick 去背景 (抠图专用)
- 存储连接应用服务器简单入门
- MySQL连接查询—自身连接
- 【ubuntu查看显卡、配置显卡、cuda、cudnn】
热门文章
- lisp如何绘制梯形_建筑考研 | 如何用数据库思维拓宽设计思路?(以清华考研快题为例)...
- 待起飞的の集训8.5
- router优点 vue_Vue 出场率99%的面试题
- 在表达式 T(n) = 2T(n/2) + O(1) 与 T(1) = O(1) 中,T(n) 的时间复杂度为多少?
- Codeforces Round #284 (Div. 2): D. Name That Tune(概率DP)
- bzoj 3036: 绿豆蛙的归宿(Dp)
- bzoj 1665: [Usaco2006 Open]The Climbing Wall 攀岩(最短路)
- 吴恩达神经网络和深度学习-学习笔记-28-端到端的深度学习(end-to-end deep learning )
- python爬虫案例——百度贴吧数据采集
- 错误RuntimeError: Invalid DISPLAY variable