poj 2388 Who's in the Middle
来源:互联网 发布:linux下php言编程ide 编辑:程序博客网 时间:2024/05/18 09:05
Who's in the Middle
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 39218 Accepted: 22785
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
提示
题意:
不废话了,叫你排序输出最中间的那个值。
思路:
看楼上。
示例程序
Source CodeProblem: 2388Code Length: 558BMemory: 428KTime: 32MSLanguage: GCCResult: Accepted#include <stdio.h>int a[10000];void quicksort(int l,int r){ int i=l,j=r,key=a[i]; if(i>=j) { return; } while(i<j) { while(i<j&&key<=a[j]) { j--; } a[i]=a[j]; while(i<j&&key>=a[i]) { i++; } a[j]=a[i]; } a[i]=key; quicksort(l,i-1); quicksort(i+1,r);}int main(){ int n,i; scanf("%d",&n); for(i=0;n>i;i++) { scanf("%d",&a[i]); } quicksort(0,n-1); printf("%d",a[n/2]); return 0;}
0 0
- POJ--2388 Who's in the Middle
- poj 2388 Who's in the Middle
- POJ-2388 who's in the middle
- poj-2388 Who's in the Middle
- poj 2388 Who's in the Middle
- POJ 2388 Who's in the Middle
- poj 2388 Who's in the Middle
- POJ 2388 Who's in the Middle
- Poj 2388 Who's in the Middle
- POJ 2388 Who's in the Middle
- POJ 2388 Who's in the Middle
- poj 2388 Who's in the Middle
- POJ-2388-Who's in the Middle
- poj 2388 Who's in the Middle
- POJ 2388 Who's in the Middle
- poj 2388 Who's in the Middle
- Who's in the Middle(poj 2388)
- POJ 2388:Who's in the Middle
- VC隐藏任务栏,让窗口全屏
- 师兄帮帮我
- Cow Marathon
- iOS pop到指定的页面
- 【POJ】[1985]Cow Marathon
- poj 2388 Who's in the Middle
- 求最长上升/下降子序列【O(nlgn)】
- Python学习笔记(三)-- 数据结构
- 《JAVA并发编程实践》读书笔记(三)
- java位运算
- Android OpenGL ES学习笔记之常用API
- 第一次机房收费系统总结
- Android收起软键盘,隐藏软键盘
- Mybatis学习笔记---day01基础知识