poj2388---求奇数个数字的最中间的数

#include <stdio.h>
#include <stdlib.h>
int cmp(const void *a,const void *b)
{
    return (*(int *)a-*(int *)b);
}

int main()
{
    int n,arr[10001],i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    qsort(arr,n,sizeof(arr[0]),cmp);
    printf("%d",arr[n / 2]);
    return 0;
}
View Code

find the median amount of milk given such that at least half the cows give the same amount of milk or more and at least half give the same or less.

一列数排序过后(奇数个),最中间的数一定是大于或等于左边的数,最中间的数一定是小于或者等于右边的数,而且两边各一半

posted @ 2015-06-14 11:05  Gabyler  阅读(374)  评论(0编辑  收藏  举报