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.
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
3
Hint
INPUT DETAILS:
Five cows with milk outputs of 1..5
OUTPUT DETAILS:
1 and 2 are below 3; 4 and 5 are above 3.
Source
Recommend
mcqsmall
只要排一下序就可以了!
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int num,i;
int arr[10050];
while(scanf("%d",&num)!=EOF)
{
for(i=0;i<num;i++)
cin>>arr[i];
sort(arr,arr+num,cmp);
cout<<arr[(num-1)/2]<<endl;
}
return 0;
}
分享到:
相关推荐
杭电oj1000题解题报告
杭电OJ 2028代码 the rosolve of the hdu 2028
杭电OJ题目分类的叙述,可以方便去学习去做。
杭电oj 1047习题
本资源主要提供了杭电oj题目分类和自测状况两大类 可实现随机选题等功能.
杭电oj上的一些疑问,适用于初学者,可以解答一些疑问 都是一些水题
杭电OJ(1000-1099) AC 代码
杭电OJ部分威士忌的代码 杭电OJ部分威士忌的代码杭电OJ部分威士忌的代码
杭州电子科大OJ题目汇总,个人编辑,题目不多,相对简单
杭州电子科技大学 oj离线版
杭电oj分类
[生活]杭电oj部分水题 c语言源代码
这是杭电oj入门100题的题号,通过这100题可以掌握基本输入输出操作,及基本算法
这是HDUOJ上面的140道题目的答案,其中大部分都是简单题,有些太简单的就没有收集进去,代码为C/C++,全都AC了的,其中有些有具体的说明是怎么做的,例如博弈论那些
杭电oj的离线版以及题目分类的文档 更加一目了然 方便选择适合的题目做 适合暂时上不了网的用于练习
杭电离线oj(2010版),方便不能上网的朋友用,比别的版本增加了很多题!
课程资源 杭电OJ1000-1099答案 ,仅供参考...
杭电ACM2000-2011题已提交的代码!保证正确!