poj 2388 Quick_sort 求中间值
来源:互联网 发布:java base64解码图片 编辑:程序博客网 时间:2024/05/29 16:16
Who's in the Middle
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 42058 Accepted: 24335
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>#define MAX 10005int a[MAX];void quick_sort(int s[], int l, int r){if (l < r){int i = l, j = r, x = s[l];while (i < j){while(i < j && s[j] >= x) // 从右向左找第一个小于x的数j--; if(i < j) s[i++] = s[j];while(i < j && s[i] < x) // 从左向右找第一个大于等于x的数i++; if(i < j) s[j--] = s[i];}s[i] = x;quick_sort(s, l, i - 1); // 递归调用 quick_sort(s, i + 1, r);}}int main(){int T;scanf("%d",&T);for(int i=0;i<T;i++){scanf("%d",&a[i]); }quick_sort(a,0,T-1); printf("%d\n",a[T/2]);return 0;}
1 0
- poj 2388 Quick_sort 求中间值
- Quick_Sort
- quick_sort
- quick_sort
- quick_sort
- quick_sort
- quick_sort
- QUICK_SORT
- 函数重载--求中间值
- poj 2388 Who's in the Middle -- 求中间的数
- POJ 1836 Alignment 枚举中间点双向求LIS
- 求最大值,最小值及中间值
- hdu 4251 求区间的中间值
- hdu 3473划分树~~求中间值
- 函数重载——求中间值
- 求两个排序数组的中间值
- 求三个数的中间值
- php求三个数中间值
- SQL优化
- bind开启log
- text函数
- js中重写a标签的href属性和onclick事件
- Codeforces 612E
- poj 2388 Quick_sort 求中间值
- LeetCode2.Add Two Numbers
- 串口驱动程序设计详解---串口初始化(上)
- 西门子plc s7 200数据长度和数值范围及格式
- Kinetis KL8x 使用eDMA模块接收串口数据
- Jsp向Action中传集合
- eclipse安装JBoss Tools插件(必须是最新版的eclipse,否则参考第二种安装)
- 关于绑定变量关闭的情况,Oracle是如何工作的?
- Rviz可视化交互之Maker(二)