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

HDU 4981

时间:2014-12-12 19:18:22      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:acm算法   amp   math.h   c   printf   

超级水的一道题。上题目

Problem Description
A median in a sequence with the length of nbubuko.com,布布扣 is an element which occupies position number ?n+1bubuko.com,布布扣2bubuko.com,布布扣bubuko.com,布布扣?bubuko.com,布布扣 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 nbubuko.com,布布扣 (1n1000bubuko.com,布布扣), indicating the size of the sequence. Then in the next line, there are nbubuko.com,布布扣 integers abubuko.com,布布扣1bubuko.com,布布扣,abubuko.com,布布扣2bubuko.com,布布扣,,abubuko.com,布布扣nbubuko.com,布布扣bubuko.com,布布扣 (1abubuko.com,布布扣ibubuko.com,布布扣1000bubuko.com,布布扣), 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

 

 

让你判断五个数中(N+1)/2的位置这个数是否大于这五个数的平均数。大于就YES,反之NO。(坑点,要将五个数排序。)

上代码

#include <string.h>
#include <algorithm>
#include <stdio.h>
using namespace std;
int main()
{
    double a[1050];
    int n,i;
    while(~scanf("%d",&n))
    {
        memset(a,0,sizeof(a));
        double sum=0;
        for(i=1;i<=n;i++)
        {
            scanf("%lf",&a[i]);
            sum+=a[i];
        }
        sum=sum/n;
        sort(a+1,a+n+1);
        int mid=(n+1)/2;
        if(sum<a[mid])
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


 

HDU 4981

标签:acm算法   amp   math.h   c   printf   

原文地址:http://blog.csdn.net/sky_miange/article/details/41895599

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