杭电OJ 题 2673 shǎ崽 OrOrOrOrz 解题报告

来源:互联网 发布:男女对唱的网络歌曲 编辑:程序博客网 时间:2024/05/30 02:23

shǎ崽 OrOrOrOrz

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



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

Sample Output
5 1 4 2 3
 ——————————————————————————————————————————————————————————————
简单的排序,输出从两边输出, 我是用快排进行排序的

/************************   程序名:shǎ崽 OrOrOrOrz.c*   功能:ACM************************/#include <stdio.h>void QuickSort(int *, int, int);int Process(int *, int, int);int main(){    int N, i, j;    int array[11111];    while(scanf("%d", &N) != EOF) {        for(i = 0; i < N; i++) {            scanf("%d", array + i);        }        QuickSort(array, 0, N-1);        i = 0;        j = N-1;        while(i < j) {            printf("%d ", array[j]);            printf("%d", array[i]);            i++;            j--;            if(i < j || N % 2) {                printf(" ");            }        }        if(N % 2) {            printf("%d", array[i]);        }        printf("\n");    }    return 0;}void QuickSort(int *array, int i, int j){    int k;    if(i < j) {        k = Process(array, i, j);        QuickSort(array, i, k-1);        QuickSort(array, k+1, j);    }}int Process(int *array, int i, int j){    int x;    x = array[i];    while(i < j) {        while(array[j] >= x && i < j) {            j--;        }        array[i] = array[j];        while(array[i] <= x && i < j) {            i++;        }        array[j] = array[i];    }    array[i] = x;    return i;}


 
原创粉丝点击