HDU 1157.
2016-07-20 21:14
239 查看
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.
题意:求中位数。
就是个排序函数,然后求中间的数
#include<stdio.h> #include<algorithm> #include<iostream> using namespace std; int N,i,a[10100]; int main() { while(~scanf("%d",&N)) { for(i=0; i<N; i++) { scanf("%d",&a[i]); } sort(a,a+N); cout<<a[(N-1)/2]<<endl; } return 0; }
相关文章推荐
- jquery 杂文
- 堆排序
- UVA-10785 The Mad Numerologist
- 训练第二周之DFS(深度优先搜索)
- 烧写程序(下载程序)基础知识
- switch 中一旦 case 匹配,就会顺序执行后面的程序代码
- odoo税金处理
- 字符串变换
- 算法的时间复杂度(理论篇)
- 哈希表
- 堆排序
- 基于加速度传感器智能穿戴:神经网络以及判断过程
- Maven实战(一)--Why Maven
- hdoj 5053 the Sum of Cube [数学 立方求和]
- iOS消息推送之远程推送
- 第18章-Java IO系统
- linux 查看内核版本及发行版本
- Linux Shell里面生成随机数的一些思路分析
- 指针
- js学习第二天