zoukankan      html  css  js  c++  java
  • 杭电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 }
  • 相关阅读:
    datadog数据json格式转换prometheus文本格式
    clickhouse聚合
    iOS面试
    程序员如何快速准备面试中的算法
    李刚OC语言疯狂讲义笔记
    传智播客内部 学习网站+书籍分享
    iOS-多线程总结笔记
    iOS-简化单例模式(定义成宏 以后通用)
    iOS-单例模式(懒汉式和饿汉式)和GCD实现
    iOS-队列组
  • 原文地址:https://www.cnblogs.com/soTired/p/4725053.html
Copyright © 2011-2022 走看看