poj2388Who's in the Middle(快速排序)
来源:互联网 发布:网络推广报价方案 编辑:程序博客网 时间:2024/06/15 03:46
Who’s in the Middle
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 42776 Accepted: 24737
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.
OutputLine 1: A single integer that is the median milk output.
Sample Input
5
2
4
1
3
5
Sample Output
3
快速排序找出中位数
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <queue>#include <cmath>using namespace std;int out[10010];int qiucksort(int a[],int l,int r){ if(l<r) { int i,j,x; i=l,j=r,x=a[l]; while(i<j) { while(i<j&&a[j]>=x) { j--; } if(i<j) { a[i++]=a[j]; } while(i<j&&a[i]<x) { i++; } if(i<j) { a[j--]=a[i]; } } a[i]=x; qiucksort(a,l,i-1); qiucksort(a,i+1,r); }}int main(){ int n; //int out[10010]; scanf("%d",&n); int ave=(n+1)/2; int min=0; for(int i=1;i<=n;i++) { scanf("%d",&out[i]); } qiucksort(out,1,n); //for(int i=1;i<=n;i++) //cout<<out[i]<<endl; cout<<out[ave]<<endl; return 0;}
- poj2388Who's in the Middle(快速排序)
- poj2388Who's in the Middle【堆排序】
- poj2388Who's in the Middle
- HDU 1157(Who's in the Middle) 快速排序
- HDU 1157 Who's in the Middle (快速排序)
- 1753: [Usaco2005 qua]Who's in the Middle (快速排序)
- HDU 1157 Who's in the Middle (快速排序 or 任意排序)
- poj 2388 Who's in the Middle(快速排序求中位数)
- 快速排序浅谈——(解题报告)HDU1157和POJ2388---Who's in the Middle
- HDOJ1157 Who's in the Middle(排序)
- 2388 Who's in the Middle(简单排序)
- poj_2388 Who's in the Middle(排序)
- Who's in the Middle(poj2388 排序)
- 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 排序
- POJ2388《Who's in the Middle》方法:排序
- Linux设备驱动模型4——平台总线实践
- Java经典设计模式之七大结构型模式(附实例和详解)
- 将博客搬至CSDN
- 51Nod1116 K进制下的大数(思维)
- 用R实现一个简单的感知机
- poj2388Who's in the Middle(快速排序)
- [bzoj1057][ZJOI2007]棋盘制作
- Spring入门(二)——理解spring的AOP编程
- 第二十二讲项目1-翻转数组
- 【阶段小结】库房管理需求敲定
- ACM-并查集- How Many Tables-HDU
- Java经典设计模式之十一种行为型模式(附实例和详解)
- Android使用友盟集成QQ、微信、微博等第三方登录
- 自定义分页功能的实现代码