题意;
寻找中位数
利用快速排序来寻找中位数。
 #include <iostream>
using namespace std;
int N;
int op[];
int Median(int left,int right,int pos){
int l=left-,r=left;
int pirior=op[right];
for(int i=left;i<right;i++){
if(op[i]<pirior){
int temp=op[i];
op[i]=op[r];
op[r]=temp;
r++;
l++;
}
}
int t=op[right];
op[right]=op[r];
op[r]=t;
if(r==pos){
return op[r];
}else if(r<pos){
return Median(r+,right,pos);
}if(r>pos){
return Median(left,r-,pos);
} }
int main() {
cin>>N;
for(int i=;i<N;i++){
cin>>op[i];
}
int mid=Median(,N-,N/);
cout<<mid<<endl;
return ;
}
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 34962   Accepted: 20387

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.

Output

* Line 1: A single integer that is the median milk output.

Sample Input

5
2
4
1
3
5

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.

Who's in the Middle - poj 2388 (快速排序寻找中位数)的更多相关文章

  1. poj 2388 insert sorting

    /** \brief poj 2388 insert sorting 2015 6 12 * * \param * \param * \return * */ #include <iostrea ...

  2. POJ 2388&&2299

    排序(水题)专题,毕竟如果只排序不进行任何操作都是极其简单的. 事实上,排序算法十分常用,在各类高级的算法中往往扮演着一个辅助的部分. 它看上去很普通,但实际的作用却很大.许多算法在失去排序后将会无法 ...

  3. poj 2388 Who's in the Middle(快速排序求中位数)

    一.Description FJ is surveying his herd to find the most average cow. He wants to know how much milk ...

  4. POJ 2388 Who's in the Middle(水~奇数个数排序求中位数)

    题目链接:http://poj.org/problem?id=2388 题目大意: 奇数个数排序求中位数 解题思路:看代码吧! AC Code: #include<stdio.h> #in ...

  5. poj 2388 Who's in the Middle

    点击打开链接 Who's in the Middle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28324   Acce ...

  6. POJ 2388 Who's in the Middle (快速选择算法:O(N)求数列第K大)

    [题意]求数列中间项. ---这里可以扩展到数列第K项. 第一次做的时候直接排序水过了= =--这一次回头来学O(N)的快速选择算法. 快速选择算法基于快速排序的过程,每个阶段我们选择一个数为基准,并 ...

  7. poj 2388 Who&#39;s in the Middle

    Who's in the Middle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31149   Accepted: 1 ...

  8. POJ 2388:Who&#39;s in the Middle

    Who's in the Middle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 31015   Accepted: 1 ...

  9. POJ 2388(排序)

    http://poj.org/problem?id=2388 题意:就N个数的中位数. 思路:用快排就行了.但我没用快排,我自己写了一个堆来做这个题.主要还是因为堆不怎么会,这个拿来练练手. #inc ...

随机推荐

  1. 纯JS操作获取桌面路径方法

    //active 控件获取当前用户的桌面的路径的方法 var wsh = new ActiveXObject("wscript.shell"); listall(wsh.Speci ...

  2. VR开发者必看:4大最为值得关注的内容平台【转】

            时间 2016-01-19 14:12:57 原文  http://www.sfw.cn/xinwen/478369.html 主题 虚拟现实 Oculus 对很多有意涉及VR行业的内 ...

  3. (转)MFC的GUI窗口使用Console输出函数printf

    原文链接 在GUI程序中使用printf函数: #include <io.h> #include <fcntl.h> void InitConsole() { ; FILE* ...

  4. HDU 4008 Parent and son LCA+树形dp

    题意: 给定case数 给定n个点的树,m个询问 以下n-1行给出树边 m个询问 x y 问:以x为根.y子树下 y的最小点标的儿子节点 和子孙节点 思路: 用son[u][0] 表示u的最小儿子 s ...

  5. REOBJECT structure

    REOBJECT structure   包含丰富编辑控件中的OLE或图像对象的信息. Syntax 语法 typedef struct _reobject { DWORD cbStruct; LON ...

  6. CocoSourcesCS 4

    /*------------------------------------------------------------------------- ParserGen.cs -- Generati ...

  7. 说说css伪元素::before和::after,你就会明白我们为什么需要它

    wxml <view class='weui-loading'>#000</view> <view class='btn'><text class='gree ...

  8. Unity3D研究院之IOS本地消息通知LocalNotification的使用(六十七)

    http://www.xuanyusong.com/archives/2632    现在的游戏里一般都会有本地消息,比如每天定时12点或者下午6点告诉玩家进入游戏领取体力.这种东西没必要服务器去推送 ...

  9. npm install --no-bin-links中的参数“no-bin-links”表示什么意思

    npm install --no-bin-links中的参数"no-bin-links"表示什么意思

  10. C# Windows form application 播放小视频

    1. 下载direcly-show lib DLL点击打开链接 2. DxPlay.cs (能够在下载的样例中找到):    public class DxPlay : IDisposable { e ...