(Hdu step 1.3.8) Who's in the middle (sort)

Source: Internet
Author: User

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 Input
524135
Sample Output
3Hint 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.