当前位置: 代码迷 >> 综合 >> HDU 4981 Goffi and Median——BestCoder Round #6
  详细解决方案

HDU 4981 Goffi and Median——BestCoder Round #6

热度:16   发布时间:2023-12-12 10:59:08.0

Goffi and Median

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)


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

Source
BestCoder Round #6
/****************************************************/

出题人的解题思路:

题意: 给你一个序列,判断中位数大还是平均数大

分析: 直接搞就好了

给所有数排个序,拿中位数跟所有数的平均数比较一下大小就可以了,毕竟是BestCoder的第一题,总要水一点的嘛

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<stdlib.h>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#define exp 1e-10
using namespace std;
const int N = 1005;
const int inf = 2147483647;
const int mod = 2009;
int s[N];
int main()
{int n,i,sum;while(~scanf("%d",&n)){for(sum=i=0;i<n;i++){scanf("%d",&s[i]);sum+=s[i];}sort(s,s+n);if(1.0*sum/n>=s[(n+1)/2-1])puts("NO");elseputs("YES");}return 0;
}
菜鸟成长记


  相关解决方案