[2388]Who's in the Middle(水题)
2014-09-21 20:46
344 查看
Who's in the Middle
Description
FJ is surveying his 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 < 10,000) 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 that is the milk output of one cow.
Output
* Line 1: A single integer that is the median milk output.
Sample Input
Sample Output
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 31982 | Accepted: 18621 |
FJ is surveying his 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 < 10,000) 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 that is the milk output of one cow.
Output
* Line 1: A single integer that is the median milk output.
Sample Input
5 2 4 1 3 5
Sample Output
3
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <iostream> using namespace std; int a[10100]; int main() { int n; int i,j,t; cin>>n; for(i=0;i<n;i++) cin>>a[i]; for(i=0;i<n-1;i++) for(j=0;j<n-i-1;j++) if(a[j]>a[j+1]) { t=a[j]; a[j]=a[j+1]; a[j+1]=t; } cout<<a[n/2]<<endl; return 0; }
相关文章推荐
- Who's in the Middle - POJ 2388 水题
- POJ 2388 Who's in the Middle
- poj 2388 Who's in the Middle
- POJ 2388:Who's in the Middle
- POJ_2388 Who's in the Middle
- poj 2388 Who's in the Middle
- POJ 2388-Who's in the Middle
- 第K小数 uva 10041 - Vito's Family poj 2388 Who's in the Middle
- POJ 2388 Who's in the Middle
- PKU_ACM_2388_Who's in the Middle
- POJ 2388 Who's in the Middle(排序)
- POJ 2388 Who's in the Middle(堆排序)
- poj 2388 Who's in the Middle
- POJ-2388-Who's in the Middle
- Pku acm 2388 Who's in the Middle 排序算法解题报告(二)----计数排序
- POJ 2388 Who's in the Middle 快排解法
- POJ 一 2388 Who's in the Middle
- poj-2388 Who's in the Middle
- POJ--2388 Who's in the Middle
- POJ 2388 Who's in the Middle