Acmer in HDU-ACM team are ambitious, especially shǎ崽, he can spend time in Internet bar doing problems overnight. So many girls want to meet and Orz him. But Orz him is not that easy.You must solve this problem first. 
The problem is : 
Give you a sequence of distinct integers, choose numbers as following : first choose the biggest, then smallest, then second biggest, second smallest etc. Until all the numbers was chosen . 
For example, give you 1 2 3 4 5, you should output 5 1 4 2 3 

InputThere are multiple test cases, each case begins with one integer N(1 <= N <= 10000), following N distinct integers.OutputOutput a sequence of distinct integers described above.Sample Input

5
1 2 3 4 5

Sample Output

5 1 4 2 3
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std; int main(){
int a[10000],n,i,j;
while(~scanf("%d",&n)){
for(i=0;i<n;++i)
scanf("%d",&a[i]);
sort(a,a+n);
i=0;//!!
j=n-1;
while(i<j){
printf("%d %d",a[j],a[i]);
if(i+1!=j)printf(" ");
++i;
--j;//从两变填入
}
if(i==j)printf("%d",a[i]);
printf("\n");
}
return 0;
}

  

HDU 2673 (排序)的更多相关文章

  1. HDU——1106排序(istringstream的使用、STLvector练习)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...

  2. hdu 1106 排序(水题)

    题目描述: 输入一行数字,如果我们把这行数字中的'5'都看成空格,那么就得到一行用空格分割的若干非负整数(可能有些整数以'0'开头,这些头部的'0'应该被忽略掉,除非这个整数就是由若干个'0'组成的, ...

  3. HDU 1106 排序 题解

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  4. hdu 1106:排序(水题,字符串处理 + 排序)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  5. hdu 3466 排序01背包

    也是好题,带限制的01背包,先排序,再背包 这题因为涉及到q,所以不能直接就01背包了.因为如果一个物品是5 9,一个物品是5 6,对第一个进行背包的时候只有dp[9],dp[10],…,dp[m], ...

  6. HDOJ(HDU) 2109 Fighting for HDU(简单排序比较)

    Problem Description 在上一回,我们让你猜测海东集团用地的形状,你猜对了吗?不管结果如何,都没关系,下面我继续向大家讲解海东集团的发展情况: 在最初的两年里,HDU发展非常迅速,综合 ...

  7. hdu 1106 排序

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...

  8. hdu EXCEL排序

    Problem Description Excel可以对一组纪录按任意指定列排序.现请你编写程序实现类似功能. Input 测试输入包含若干测试用例.每个测试用例的第1行包含两个整数 N (<= ...

  9. hdu2108 Shape of HDU 极角排序判断多边形

    Problem Description 话说上回讲到海东集团推选老总的事情,最终的结果是XHD以微弱优势当选,从此以后,"徐队"的称呼逐渐被"徐总"所取代,海东 ...

随机推荐

  1. BZOJ4537 HNOI2016最小公倍数(莫队+并查集)

    考虑边只有一种权值的简化情况.那么当且仅当两点可以通过边权<=x的边连通,且连通块内最大边权为x时,两点间存在路径max为x的路径.可以发现两种权值是类似的,当且仅当两点可以通过边权1<= ...

  2. 【转】Visio画用例模型图竟然没有include关系

    转自:http://blog.csdn.net/shuixin536/article/details/8289746 由于电脑上没有安装Rose,因此决定用visio来画UML中的用例模型图,在绘制的 ...

  3. day10_plus

    刚才发奖哈哈哈 想不到被惨虐的我还能混个牌子哈哈哈好开心

  4. NOIP2012 洛谷P1084 疫情控制

    Description: H 国有 n 个城市,这 n 个城市用 n-1 条双向道路相互连通构成一棵树,1 号城市是首都,也是树中的根节点. H 国的首都爆发了一种危害性极高的传染病.当局为了控制疫情 ...

  5. codeforces 1060 D

    https://codeforces.com/contest/1060/problem/D 题意:你可以用1个及以上的圆桌,给n个人排座位,每个人左边需要有Li个空凳子,右边需要有Ri个空凳子,问你最 ...

  6. webstorm中把style的内容隐藏,如何把style的内容展开?

    我们经常看到在webstorm中style的内容以...表示如下图所示,只有把光标移到上面时才会看到内容: 如何把上述的style的内容展开呢? 请按一下步骤操作: 第一步:File------> ...

  7. Spring学习-- IOC 容器中 bean 的生命周期

    Spring IOC 容器可以管理 bean 的生命周期 , Spring 允许在 bean 声明周期的特定点执行定制的任务. Spring IOC 容器对 bean 的生命周期进行管理的过程: 通过 ...

  8. bzoj 1576: [Usaco2009 Jan]安全路经Travel——并查集+dijkstra

    Description Input * 第一行: 两个空格分开的数, N和M * 第2..M+1行: 三个空格分开的数a_i, b_i,和t_i Output * 第1..N-1行: 第i行包含一个数 ...

  9. python3 匿名函数,map/reduce/filter等函数结合应用

    匿名函数就是不需要显式的指定函数 # 平方函数 def func1(x): return x**2 print(func1) # 平方函数匿名函数写法 func2=lambda x:x**2 prin ...

  10. algorithm ch7 QuickSort

    快速排序是基于分治模式的排序,它将数组a[p,...,r]分成两个子数组a[p,...q-1],a[q+1,...,r],使得a[p,...,q-1]中每个元素都小于a[q],而且小于等于a[q+1, ...