HDOJ1157 Who's in the Middle(排序)
来源:互联网 发布:4g网络优化工程师前景 编辑:程序博客网 时间:2024/06/04 19:18
Who's in the Middle
Problem 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.
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.
* 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
524135
Sample Output
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;
}
0 0
- HDOJ1157 Who's in the Middle(排序)
- 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(排序)
- Who's in the Middle(poj2388 排序)
- Who's in the Middle
- Who's in the Middle
- Who's in the Middle
- Who's in the Middle
- Who's in the Middle
- Who's in the Middle
- Who's in the Middle
- Who's in the Middle
- Who's in the Middle
- Who's in the Middle
- Who's in the Middle
- Who's in the Middle
- hdu1575Tr A
- base
- pb中describe、Evaluate、Lookupdisplay的用法
- "Mac OS X"录屏幕视频并转成gif
- 改写oauth2.0过程中的问题
- HDOJ1157 Who's in the Middle(排序)
- 们从未真正长大,我们只是在别人面前学会了假装
- RFID学习(六)通讯协议概述
- bat 删除n天前的文件
- MyEclipse中光标不显示
- geoserver由windows迁移到linux64位系统
- mysql 取前几个值
- HDU 1465 不容易系列之一【错排】
- java nio