首页 > 代码库 > HDU 4981 Goffi and Median

HDU 4981 Goffi and Median

题解:排序取中位数,然后与平均数比较即可。

#include <cstdio>#include <algorithm>using namespace std;double a[1005],ave,med,sum; int n;int main(){    while(~scanf("%d",&n)){        sum=0;        for(int i=1;i<=n;i++){scanf("%lf",&a[i]);sum+=a[i];}        sort(a+1,a+n+1);        med=a[(n+1)/2];        ave=sum/(double)n;        if(med<=ave)puts("NO");else puts("YES");    }return 0; }

HDU 4981 Goffi and Median