• 杭电2673--shǎ崽 OrOrOrOrz


    shǎ崽 OrOrOrOrz

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 7821    Accepted Submission(s): 3735


    Problem 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
     

     

    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
    5 1 2 3 4 5
     

     

    Sample Output
    5 1 4 2 3
     

     

    Author
    WhereIsHeroFrom
     

     

    Source
     

     

    Recommend
    lcy   |   We have carefully selected several similar problems for you:  2672 2674 2668 1040 1236 
     1 #include <cstdio>
     2 #include <iostream>
     3 #include <algorithm>
     4 #include <cstring>
     5 using namespace std;
     6 int num[10010];
     7 int main()
     8 {
     9     int n;
    10     while(~scanf("%d", &n))
    11     {
    12         for(int i = 0; i < n; i++)
    13             scanf("%d", &num[i]);
    14         sort(num, num + n);
    15         if(n & 1)
    16         {
    17             for(int j = 0, i = n-1; i > n/2; j++, i--)
    18                 printf("%d %d ", num[i], num[j]);
    19             printf("%d
    ", num[n/2]);
    20         }
    21         else
    22         {
    23             for(int j = 0, i = n-1; i >= n/2; j++, i--)
    24             {
    25                 if(j == 0)
    26                     printf("%d %d", num[i], num[j]);
    27                 else
    28                     printf(" %d %d", num[i], num[j]);
    29             }
    30             printf("
    ");
    31         }
    32     }
    33     
    34     return 0;
    35 }
  • 相关阅读:
    Linux 下杀毒可用工具 clamav
    Docker 添加环境系统文件配置
    Docker 空间大小设置
    Docker 扩容 容器空间大小
    bzoj 1088 DP
    bzoj 1096 斜率优化DP
    spoj p104 Matrix-Tree定理
    bzoj 1016 深搜
    WC后记
    bzoj 1301 后缀数组
  • 原文地址:https://www.cnblogs.com/soTired/p/4725053.html
Copyright © 2020-2023  润新知