ACM水题系列 HDOJ2673
来源:互联网 发布:gta5女人物捏脸数据 编辑:程序博客网 时间:2024/05/18 01:11
shǎ崽 OrOrOrOrz
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4085 Accepted Submission(s): 1264Problem Description
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
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
Input
There are multiple test cases, each case begins with one integer N(1 <= N <= 10000), following N distinct integers.
Output
Output a sequence of distinct integers described above.
Sample Input
51 2 3 4 5
Sample Output
5 1 4 2 3
思路:排序,首尾交叉输出。
坑点:最后一次输出数据后不能再输出空格。
#include <iostream>#include <vector>#include <algorithm>using namespace std;int main(){ int t,a[10001]; while(cin>>t){ for(int i=0;i<t;i++) cin>>a[i]; sort(a,a+t); int flag = t-1,sum =1; for(int i=0;i<t;i++,sum++){ if(i%2 == 0){ if(sum == t) cout<<a[flag]<<endl; else cout<<a[flag]<<" "; flag--; } else{ if(sum == t) cout <<a[i/2]<<endl; else cout<<a[i/2]<<" "; } } } return 0;}
0 0
- ACM水题系列 HDOJ2673
- ACM水题系列 HDOJ1038
- ACM水题系列 HDOJ2393
- ACM水题系列 HDOJ2629
- ACM水题系列 HDOJ2550
- ACM水题系列 HDOJ2093
- ACM水题系列 HDOJ 1064
- ACM水题系列 HDOJ 1326
- ACM水题系列 HDOJ 1061
- acm教主系列
- ACM动态规划系列
- ACM(贪心系列)
- 每日一题系列 - Compacting Stickers (ACM竞赛题)
- ACM-简单题之不容易系列之一——hdu1465
- acm题目之教主系列
- 南阳acm士兵杀敌系列
- acm题
- acm题
- ACM水题系列 HDOJ2550
- 了解网站页面的点击情况(续)
- 了解网站页面的点击情况
- Android SDK开发包国内下载地址
- 网站的活跃用户与流失用户
- ACM水题系列 HDOJ2673
- ATSC制数字电视机顶盒研究
- C++11新特性(四)static_assert, share_ptr, unique_ptr简单使用
- ACM水题系列 HDOJ2093
- 如何用SQL语句批量替换数据库字符串
- ch13.JSP标准标签库
- JS中Array数组的三大属性用法
- 键盘的关闭打开通知
- 《iOS开发指南:从零基础到App Store上架(第2版 )(3).pdf》