poj 2388 Who's in the Middle
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 28324 | Accepted: 16396 |
Description
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
* Lines 2..N+1: Each line contains a single integer that is the milk output of one cow.
Output
Sample Input
5
2
4
1
3
5
Sample Output
3
Hint
Five cows with milk outputs of 1..5
OUTPUT DETAILS:
1 and 2 are below 3; 4 and 5 are above 3.
没什么好说的,快排找中位数
#include <iostream>
#include<algorithm>
using namespace std; int main(int argc, char *argv[])
{
int a[10000]={0};
int n=0;
cin>>n;
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
cout<<a[(n-1)/2]<<endl;
return 0;
}
poj 2388 Who's in the Middle的更多相关文章
- POJ 2388 Who's in the Middle(水~奇数个数排序求中位数)
题目链接:http://poj.org/problem?id=2388 题目大意: 奇数个数排序求中位数 解题思路:看代码吧! AC Code: #include<stdio.h> #in ...
- POJ 2388 Who's in the Middle (快速选择算法:O(N)求数列第K大)
[题意]求数列中间项. ---这里可以扩展到数列第K项. 第一次做的时候直接排序水过了= =--这一次回头来学O(N)的快速选择算法. 快速选择算法基于快速排序的过程,每个阶段我们选择一个数为基准,并 ...
- 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 ...
- poj 2388 insert sorting
/** \brief poj 2388 insert sorting 2015 6 12 * * \param * \param * \return * */ #include <iostrea ...
- poj 2388 Who's in the Middle
Who's in the Middle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 31149 Accepted: 1 ...
- POJ 2388:Who's in the Middle
Who's in the Middle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 31015 Accepted: 1 ...
- Who's in the Middle - poj 2388 (快速排序寻找中位数)
题意; 寻找中位数 利用快速排序来寻找中位数. #include <iostream> using namespace std; int N; ]; int Median(int left ...
- POJ 2388(排序)
http://poj.org/problem?id=2388 题意:就N个数的中位数. 思路:用快排就行了.但我没用快排,我自己写了一个堆来做这个题.主要还是因为堆不怎么会,这个拿来练练手. #inc ...
- POJ 2388&&2299
排序(水题)专题,毕竟如果只排序不进行任何操作都是极其简单的. 事实上,排序算法十分常用,在各类高级的算法中往往扮演着一个辅助的部分. 它看上去很普通,但实际的作用却很大.许多算法在失去排序后将会无法 ...
随机推荐
- 通过CSS禁用页面模块的复制和粘贴功能
样式代码: -moz-user-select: none; -webkit-user-select: none; -ms-user-select: none; -khtml-user-select: ...
- JavaScript中知而不全的this (转)
原文引自:http://www.cnblogs.com/snandy/p/4773184.html 都说 JavaScript 是一种很灵活的语言,这其实也可以说它是一个混乱的语言.它把函数式编程和面 ...
- Jquery遍历元素
页面中所有的checkBox遍历: <script type="text/javascript" src="/jquery/jquery.js">& ...
- WordPress中"无法将上传的文件移动至"错误的解决方法
#chown -R www:www /wwwroot 今天在网页上传图片到博客,结果提示:“无法将上传的文件移动至 /home/wwwroot/wp-content/uploads/2013/”,郁闷 ...
- Javascript 数组之判断取值和数组取值
题目一:var arr = [ '100px', 'abc'-6, [], -98765, 34, -2, 0, '300', , function(){alert(1);}, null, docum ...
- mysql四种事务隔离级的说明
·未提交读(Read Uncommitted):允许脏读,也就是可能读取到其他会话中未提交事务修改的数据 ·提交读(Read Committed):只能读取到已经提交的数据.Oracle等多数数据库默 ...
- [原]Fedora 20的yum配置
新装了一套Fedora 20操作系统,又要开始配置yum了.下面总结以下步骤: 1.下载国内比较快的yum源 推荐163的yum源,sohu的yum源也不错,我一般就装第一个,安装163 yum源主页 ...
- 遇到 Error creating the Web Proxy specified in the 'system.net/defaultProxy' configuration section的解决办法
用记事本编辑*.EXE.config,在“<system.net>”节点加入<defaultProxy> <proxy usesystemdefault="Fa ...
- wcf stream 不知道长度的情况下,读取stream
http://bbs.csdn.net/topics/360163784 string filepath = @"http://ww4.sinaimg.cn/thumbnail/6741e0 ...
- 几个关于wcf、rest服务的好帖子
//http://blog.csdn.net/fangxing80/article/details/6247297 //http://msdn.microsoft.com/zh-cn/magazin ...