【CUGBACM15级BC第六场 A】hdu 4981 Goffi and Median
2017-08-31 20:35
435 查看
Goffi and Median
[align=center]Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1078 Accepted Submission(s): 569
[/align]
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each case, if Goffi like the sequence, output "YES" in a line. Otherwise, output "NO".
[align=left]Sample Input[/align]
5
1 2 3 4 5
4
1 5 6 6
[align=left]Sample Output[/align]
NO
YES
思路:排序就可以得到中间数,然后总和和中间数*n比较一下即可
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; #define N 1100 double a ; int main() { int n; while (~scanf("%d", &n)) { double sum = 0; for (int i = 1; i <= n; i++) { scanf("%lf", &a[i]); sum += a[i]; } int men = (n + 1) / 2; sum /= n; sort(a + 1, a + 1 + n); if (a[men] <= sum) { printf("NO\n"); } else { printf("YES\n"); } } return 0; }
相关文章推荐
- 【CUGBACM15级BC第六场 B】hdu 4982 Goffi and Squary Partition
- HDU—— 4981 Goffi and Median
- 【CUGBACM15级BC第7场 B】hdu 4986 Little Pony and Alohomora Part I
- hdu 4981 Goffi and Median(水题)
- HDU 4981 Goffi and Median(水)
- [BestCoder Round #6] hdu 4981 Goffi and Median (水题)
- 【CUGBACM15级BC第25场 A】hdu 5154 Harry and Magical Computer
- hdu 4981 Goffi and Median(BestCoder Round #6)
- 【CUGBACM15级BC第11场 A】hdu 5054 Alice and Bob
- HDU 4981 Goffi and Median(水)
- 【CUGBACM15级BC第22场 A】hdu 5142 NPY and FFT
- hdu 4981 Goffi and Median(水题)
- 【CUGBACM15级BC第22场 C】hdu 5144 NPY and shot
- 【CUGBACM15级BC第27场 A】hdu 5162 Jump and Jump...
- 【CUGBACM15级BC第22场 B】hdu 5143 NPY and arithmetic progression
- HDU 4981 Goffi and Median(BestCoder Round #6 1001)
- HDU 4981 Goffi and Median
- 【CUGBACM15级BC第25场 B】hdu 5155 Harry And Magic Box
- 【CUGBACM15级BC第11场 B】hdu 5055 Bob and math problem
- 【CUGBACM15级BC第7场 A】hdu 4985 Little Pony and Permutation