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

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

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;
}
时间: 2025-01-04 08:15:32

[BestCoder Round #6] hdu 4981 Goffi and Median (水题)的相关文章

HDU 4981 Goffi and Median(水)

HDU 4981 Goffi and Median 思路:排序就可以得到中间数,然后总和和中间数*n比较一下即可 代码: #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const int N = 1005; int n, a[N], sum; int main() { while (~scanf("%d&

[BestCoder Round #3] hdu 4907 Task schedule (模拟简单题)

Task schedule Problem Description 有一台机器,并且给你这台机器的工作表,工作表上有n个任务,机器在ti时间执行第i个任务,1秒即可完成1个任务. 有m个询问,每个询问有一个数字q,表示如果在q时间有一个工作表之外的任务请求,请计算何时这个任务才能被执行. 机器总是按照工作表执行,当机器空闲时立即执行工作表之外的任务请求. Input 输入的第一行包含一个整数T, 表示一共有T组测试数据. 对于每组测试数据: 第一行是两个数字n, m,表示工作表里面有n个任务,

[BestCoder Round #6] hdu 4982 Goffi and Squary Partition(构造)

Goffi and Squary Partition Problem Description Recently, Goffi is interested in squary partition of integers. A set X of k distinct positive integers is called squary partition of n if and only if it satisfies the following conditions: the sum of k p

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];}

Bestcoder round #65 &amp;&amp; hdu 5592 ZYB&#39;s Premutation 线段树

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 175    Accepted Submission(s): 74 Problem Description ZYB has a premutation P,but he only remeber the reverse log of each prefix of the premutat

Bestcoder round #65 &amp;&amp; hdu 5593 ZYB&#39;s Tree 树形dp

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 354    Accepted Submission(s): 100 Problem Description ZYB has a tree with N nodes,now he wants you to solve the numbers of nodes distanced no m

[BestCoder Round #3] hdu 4909 String (状压,计数)

String Problem Description You hava a non-empty string which consists of lowercase English letters and may contain at most one '?'. Let's choose non-empty substring G from S (it can be G = S). A substring of a string is a continuous subsequence of th

[BestCoder Round #4] hdu 4932 Miaomiao&#39;s Geometry (贪心)

Miaomiao's Geometry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 363    Accepted Submission(s): 92 Problem Description There are N point on X-axis . Miaomiao would like to cover them ALL by

[BestCoder Round #4] hdu 4931 Happy Three Friends

Happy Three Friends Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 70    Accepted Submission(s): 62 Problem Description Dong-hao , Grandpa Shawn , Beautful-leg Mzry are good friends. One day ,