首页 > 其他 > 详细

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

时间:2015-06-14 12:23:11      阅读:168      评论:0      收藏:0      [点我收藏+]
技术分享
#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.

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

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

原文:http://www.cnblogs.com/gabygoole/p/4574774.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!