1016 average cow

1016 Problem Q

    FJ is surveying hisherd to find the most average cow. He wants to know how much milk this 'median'cow gives: half of the cows give as much or more than the median; half give asmuch or less. 

    题目概述:计算给定一组数的中值

    思路:要找到所给数据的中值,需要先对其进行排序,然后做出判断。

    感想:本题在解决上难度不大,最重要的就是排序准确的找到其中值,下面附上ac代码!

#include<iostream>

#include <algorithm>

using namespace std;

int main(){

    inti,n,m,a[10001];

   cin>>n;

   for(i=0;i<n;i++) cin>>a[i];

    sort(a,a+n);

    m=(n-1)/2;

   cout<<a[m]<<endl;

}

你可能感兴趣的:(1016 average cow)