题意;
寻找中位数
利用快速排序来寻找中位数。
 #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. Oracle TRCA 工具 说明 10046

    本篇文章主要介绍了"Oracle TRCA 工具 说明 ",主要涉及到Oracle TRCA 工具 说明 方面的内容,对于Oracle TRCA 工具 说明 感兴趣的同学可以参考一 ...

  2. vscode monokai

    https://studiostyl.es/schemes/sublime-text-3-monokai

  3. 转载:win10 下安装Oracle 11g(问题:环境不满足最低要求)

    安装oracle11g时遇到INS-13001环境不满足最低要求 在以管理员身份运行setup.exe之后,出现了:[INS-13001]环境不满足最低要求,通过网上搜索之后找到了解决途径 首先,打开 ...

  4. oracle解决连接池不足

       select count(*) from v$process;----系统有多少连接数  select value from v$parameter where name = 'processe ...

  5. cs-HtmlHelpers

    ylbtech-Unitity: cs-HtmlHelpers PagingHelpers.cs  SelectInputHelpers.cs TreeHelpers.cs 1.A,效果图返回顶部   ...

  6. ES6/ES2015核心内容(上)

    ECMAScript 6(以下简称ES6)是JavaScript语言的下一代标准.因为当前版本的ES6是在2015年发布的,所以又称ECMAScript 2015.也就是说,ES6就是ES2015. ...

  7. 【proxy agent资料】

    参考资料: GoAgent使用方法, 2015年最新FQ方法总结:http://www.bianlei.com/we-wanna-see-the-world/ 配置Android支持GAE Proxy ...

  8. Centos中mount命令挂载windows7共享文件夹

    1)  在ip:10.4.35.77的windows机器上新建用户.这里新建username:myshare,password:myshare123. 选择 [计算机]右键 选择[管理],本地用户和组 ...

  9. CMake 设置Target输出目录和后缀名

    一. SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../bin) 上面的语句能设置可执行文件的输出目录 在Win + VS环境下,会自动在你所设置 ...

  10. FBX导入错误 :ImportFBX Errors:

    原地址:http://www.cnblogs.com/lopezycj/archive/2012/05/16/unity3d_tuchao.html Unity3D吐槽1--FBX导入 Unity3d ...