Topic:
| Who's in the middle |
| Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) |
| Total submission (s): 2938 Accepted Submission (s): 1109 |
|
Problem DESCRIPTIONFJ is surveying he herd to find the most average cow. He wants to know how much milk this ' median ' cow gives:half of the cows give as much or more than the median; Half give as much or less.
Given an odd number of cows n (1 <= n <) and their milk output (1..1,000,000), find the median amount of milk Given such that at least half the cows give the same amount of milk or more and at least half give the same or less.
|
input* Line 1: A single integer N
* Lines 2..n+1:each line contains a single integer so is the milk output of one cow.
|
output* Line 1: A single integer which is the median milk output.
|
Sample Input524135 |
Sample Output3Hint INPUT details:five cows with milk outputs of 1..5 OUTPUT details:1 and 2 is below 3; 4 and 5 are above 3. |
|
| Sourceusaco 2004 November |
Recommendmcqsmall
|
Topic Analysis:
Sort, and then output the median
The code is as follows:
/* * i.cpp * * Created on:2015 January 29 * author:administrator * * #include <iostream> #include <cstdio># Include <algorithm>using namespace Std;const int maxn = 10005;int A[maxn];int main () {int n;while (scanf ("%d", &n ) {!=eof) {int i;for (i = 0; i < n; ++i) {scanf ("%d", &a[i]);} Sort (a,a+n);p rintf ("%d\n", A[N/2]);} return 0;}
(Hdu step 1.3.8) Who's in the middle (sort)