HDU 4981
来源:互联网 发布:软件项目招标 编辑:程序博客网 时间:2024/06/13 12:25
超级水的一道题。上题目
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.
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 integern (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
让你判断五个数中(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;}
0 0
- hdu 4981
- HDU 4981
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- 使用正规表达式编写更好的SQL
- IOS .pch 文件详解
- 第16周项目2-字符串长度(指针作形参)
- NGUI下UIGrid的刷新
- word 2013 长篇文档排版案例教程
- HDU 4981
- 关于电脑主板RS-232串口定义
- storm学习-Storm消息机制【转】
- 观察者模式笔记
- 弟子规 圣人训 首孝悌 次谨信
- HTML初步学习笔记
- HTML URL 编码
- cl.exe(VC编译程序)参数大全
- 阿里云Ubuntu服务器数据盘盘挂载