HDOJ1157 Who's in the Middle(排序)
2014-07-24 15:10
323 查看
Who's in the Middle
[align=left]Problem Description[/align]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.
[align=left]Input[/align]
* Line 1: A single integer N
* Lines 2..N+1: Each line contains a single integer that is the milk output of one cow.
[align=left]Output[/align]
* Line 1: A single integer that is the median milk output.
[align=left]Sample Input[/align]
5
2
4
1
3
5
[align=left]Sample Output[/align]
3
#include<stdio.h>
#include<algorithm>
using namespace std;
#define max 10000+5
int a[max];
int main()
{
int T;
int i;
while(~scanf("%d",&T))
{
for(i=0;i<T;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+T);
if(T%2==0) printf("%d\n",a[T/2]);
else printf("%d\n",a[(T+1)/2-1]);
}
return 0;
}
相关文章推荐
- HDOJ 1157 HDU 1157 Who's in the Middle ACM 1157 IN HDU
- hdoj 1157 Who's in the Middle
- hdoj 1157 Who's in the Middle(心机水题)
- HDU 1157 Who's in the Middle (快速排序 or 任意排序)
- [HDOJ 1157] Who's in the Middle (基础题)
- HDU 1157 Who's in the Middle 排序
- HDOJ 1157 Who's in the Middle(水)
- HDU 1157 Who's in the Middle(排序取中间值)
- HDU 1157(Who's in the Middle) 快速排序
- POJ2388《Who's in the Middle》方法:排序
- POJ 2388 Who's in the Middle(排序)
- HDU—— 1157 Who's in the Middle
- POJ 2388 Who's in the Middle (排序 快排复习)
- HDU 1157 Who's in the Middle
- HDU 1157 Who's in the Middle
- poj 2388 Who's in the Middle(快速排序求中位数)
- POJ 2388 Who's in the Middle 排序
- hdu-oj 1157 Who's in the Middle
- hdu 1157 Who's in the Middle (水题,中位数)
- HDU 1157 Who's in the Middle