Who's in the Middle(poj2388 排序)
来源:互联网 发布:淘宝助理百世快递模板 编辑:程序博客网 时间:2024/06/05 03:46
Who's in the Middle
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 43581 Accepted: 25190
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
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.
Five cows with milk outputs of 1..5
OUTPUT DETAILS:
1 and 2 are below 3; 4 and 5 are above 3.
Source
USACO 2004 November
求中位数。
求中位数。
#include<iostream>#include<algorithm>using namespace std;const int maxn = 10000 + 5;int milk[maxn];int main(){int n;while (cin>>n){for (int i = 0; i < n; i++){cin >> milk[i];}sort(milk, milk + n);cout << milk[(n - 1) / 2] << endl;//(n+1)/2-1==(n-1)/2} return 0;}
阅读全文
0 0
- Who's in the Middle(poj2388 排序)
- POJ2388《Who's in the Middle》方法:排序
- POJ2388 HDU1157 Who's in the Middle【中位数+排序】
- Who's in the Middle POJ2388
- poj2388 Who's in the Middle
- POJ2388-Who's in the Middle
- POJ2388-Who's in the Middle
- 快速排序浅谈——(解题报告)HDU1157和POJ2388---Who's in the Middle
- POJ2388 Who's in the Middle 快排
- poj2388——Who's in the Middle
- Who's in the Middle poj2388 vector 水题
- poj2388 Who's in the Middle 快排
- POJ2388——Who's in the Middle
- poj2388——Who's in the Middle
- 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 (快速排序)
- Java 多线程 (PART XV) wait()/notify()方法
- 数据结构C语言
- UVa 247 电话圈(Floyed判环)
- # Pixhawk开发(文档小结)
- 函数声明与函数表达式的区别
- Who's in the Middle(poj2388 排序)
- Pycharm连接GitHub笔记
- Java中的有参无参构造方法与继承的关系
- java AWT 绘图,实现弹球游戏,有实现keylistener,timer功能
- Maven项目的pom.xml常见配置(Eclipse)
- 学习计算机操作系统之-操作系统组成
- Python 筛选(finditer)
- java中锁的优化 -- JVM对synchronized的优化
- 欢迎使用CSDN-markdown编辑器