码迷,mamicode.com
首页 > 其他好文 > 详细

[BestCoder Round #6] hdu 4981 Goffi and Median (水题)

时间:2014-08-25 11:55:34      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:bestcoder

Goffi and Median




Problem Description
A median in a sequence with the length of n is an element which occupies position number ?n+12? after we sort the elements in the non-decreasing order (the elements are numbered starting with 1). A median of an array (2, 6, 1, 2, 3) is the number 2, and a median of array (0, 96, 17, 23) — the number 17.

An average of a sequence is the sum of sequence divided the size of the sequence.

Goffi likes median very much and he hates average number. So if a sequence‘s average number is larger than or equal to the median of sequence, Goffi will hate the sequence. Otherwise, Goffi will like it.

Now, your are given a sequence. Please find whether Goffi will like it or hate it.
 
Input
Input contains multiple test cases (less than 100). For each test case, the first line contains an integer n (1n1000), indicating the size of the sequence. Then in the next line, there are n integers a1,a2,,an (1ai1000), seperated by one space.
 
Output
For each case, if Goffi like the sequence, output "YES" in a line. Otherwise, output "NO".
 
Sample Input
5 1 2 3 4 5 4 1 5 6 6
 
Sample Output
NO YES
题意:

判断数字序列的中位数和平均数哪个大。

代码:

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
using namespace std;
const int maxn=1010;
int num[maxn];
int n;

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        double ave;
        double sum=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&num[i]);
            sum+=num[i];
        }
        sort(num+1,num+1+n);
        int mid=(n+1)/2;
        ave=sum/n;
        if(ave>=num[mid])
            printf("NO\n");
        else
            printf("YES\n");
    }
    return 0;
}

[BestCoder Round #6] hdu 4981 Goffi and Median (水题)

标签:bestcoder

原文地址:http://blog.csdn.net/sr_19930829/article/details/38817857

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!