题目链接:

B. z-sort

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard 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:

  1. ai ≥ ai - 1 for all even i,
  2. 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
  1. 4
    1 2 2 1
output
  1. 1 2 1 2
input
  1. 5
    1 3 2 2 5
output
  1. 1 5 2 3 2
    题意:把数列变成要求的那样,太简单就不好说了;
    AC代码:
  1. /*2014300227 652B - 6 GNU C++11 Accepted 15 ms 2168 KB*/
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int a[];
  5. int main()
  6. {
  7. int n;
  8. scanf("%d",&n);
  9. for(int i=;i<=n;i++)
  10. {
  11. scanf("%d",&a[i]);
  12. }
  13. sort(a+,a+n+);
  14. if(n%==)
  15. {
  16. for(int i=;i<=n/;i++)
  17. {
  18. printf("%d ",a[i]);
  19. printf("%d ",a[n-i+]);
  20. }
  21. }
  22. else
  23. {
  24. for(int i=;i<=n/;i++)
  25. {
  26. printf("%d ",a[i]);
  27. printf("%d ",a[n-i+]);
  28. }
  29. printf("%d",a[n/+]);
  30. }
  31.  
  32. return ;
  33. }
  1.  

codeforces 652B B. z-sort(水题)的更多相关文章

  1. Codeforces Gym 100431D Bubble Sort 水题乱搞

    原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-an ...

  2. Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树

    A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...

  3. CodeForces 489B BerSU Ball (水题 双指针)

    B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. codeforces 577B B. Modulo Sum(水题)

    题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. codeforces 696A Lorenzo Von Matterhorn 水题

    这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...

  6. CodeForces 589I Lottery (暴力,水题)

    题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...

  7. Codeforces Gym 100286G Giant Screen 水题

    Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...

  8. codeforces 710A A. King Moves(水题)

    题目链接: A. King Moves 题意: 给出king的位置,问有几个可移动的位置; 思路: 水题,没有思路; AC代码: #include <iostream> #include ...

  9. codeforces 659A A. Round House(水题)

    题目链接: A. Round House time limit per test 1 second memory limit per test 256 megabytes input standard ...

  10. codeforces 702A A. Maximum Increase(水题)

    题目链接: A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input sta ...

随机推荐

  1. java实体类如果不重写toString方法,会如何?

    先认识一下Object Object 类的 toString 方法 返回一个字符串,该字符串由类名(对象是该类的一个实例).at 标记符“@”和此对象哈希码的无符号十六进制表示组成.换句话说,该方法返 ...

  2. IEnumerable, IEnumerator接口

    IEnumerable接口 // Exposes the enumerator, which supports a simple iteration over a non-generic collec ...

  3. .net 字符串驻留

    .net中的string表达的是常量字符串. JIT编译器编译时判断遇到的常量字符串是否在内部散列表中,如果不在,添加进去.当第一次执行到含字符串的方法时,CLR会检查该字符串是否在内部的一个散列表中 ...

  4. 转载 【iOS开发】网页JS与OC交互(JavaScriptCore) OC ----->JS

      目标 本文介绍利用苹果在iOS7时发布的JavaScriptCore.framework框架进行js与OC的交互.我们想要达到的目标是: OC调用网页上的js方法 网页js调用APP中的OC方法 ...

  5. MySQL的基本操作--第一弹

    前言:在听许嵩,忆当年,意气风发 ———————————————————————————————————————————————— 好了,今天和大家同步讲解mysql的知识了.都是最基本的知识. 一. ...

  6. ios推送服务,php服务端

    本文转载至http://my.oschina.net/AStar/blog/176531   生成证书 证书生成参考:https://parse.com/tutorials/ios-push-noti ...

  7. 从零开始写一个Exporter

    前言 上一篇文章中已经给大家整体的介绍了开源监控系统Prometheus,其中Exporter作为整个系统的Agent端,通过HTTP接口暴露需要监控的数据.那么如何将用户指标通过Exporter的形 ...

  8. POJ1850&&POJ1496

    Code Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 9236   Accepted: 4405 Description ...

  9. 摘要: CentOS 6.5搭建Redis3.2.8伪分布式集群

    from https://my.oschina.net/ososchina/blog/856678     摘要: CentOS 6.5搭建Redis3.2.8伪分布式集群 前言 最近在服务器上搭建了 ...

  10. ConfigurableBeanFactory

    ConfigurableBeanFactory :关系如下 在上面这样的一个关系图中可以先看下SingletonBeanRegistry的源代码: package org.springframewor ...