[Bestcoder round #6] HDU 4981 goffi and median (water question)

Source: Internet
Author: User

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
  (
 
  1≤n≤1000
 ), indicating the size of the sequence. Then in the next line, there are 
 
  n
  integers 
 
  a1,a2,…,an
  (
 
  1≤ai≤1000
 ), seperated by one space.
Output
For each case, if Goffi like the sequence, output "YES" in a line. Otherwise, output "NO".
Sample Input
51 2 3 4 541 5 6 6
Sample output
NOYES
Question:

Determine the maximum median and mean values of the number sequence.

Code:

#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 (water question)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.