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
排序(水题)专题,毕竟如果只排序不进行任何操作都是极其简单的. 事实上,排序算法十分常用,在各类高级的算法中往往扮演着一个辅助的部分. 它看上去很普通,但实际的作用却很大.许多算法在失去排序后将会无法 ...
随机推荐
- Js RegExp对象
1 语法 1.1 直接量语法 /pattern/attributes 1.2 创建RegExp对象 new RegExp(pattern, attributes) 1.3 说明 pattern是正则表 ...
- ASP.net MVC3 报错"未找到视图“Index”或其母版视图,或没有视图引擎支持搜索的位置 "的解决方法
注意添加MVC3视图不能直接在View文件下新建视图,而是在控制器的Index 右击添加视图,就会在View下面产生一个Product文件夹(包含Index.cshtml) 就可以解决这个问题. 具体 ...
- Linux下 RabbitMQ的安装与配置
以下教程摘录自互联网并做了适当修改,测试的rabbitmq 版本为:rabbitmq-server-generic-unix-3.5.6 各版本之间会有差异!!! 一 Erlang安装 Rabbit ...
- 从MySQL到Redis 提升数据迁移的效率
场景是从MySQL中将数据导入到Redis的Hash结构中.当然,最直接的做法就是遍历MySQL数据,一条一条写入到Redis中.这样可能没什么错,但是速度会非常慢.而如果能够使MySQL的查询输出数 ...
- TP控制器(Controller)
控制器的一些方法: Maincontroller.class.php文件: <?php namespace Home\Controller; use Think\Controller; clas ...
- C# Color Table颜色对照表
.AliceBlue 240,248,255 .LightSalmon 255,160,122 .AntiqueWhite 250,235,215 .LightSeaGreen 32,178,170 ...
- android外包公司——最新案例铁血军事手机客户端(IOS & Android)
<铁血军事>Android手机客户端由铁血网开发和运营,为网友提供铁血论坛和铁血读书两大产品.使用Android手机客户端,您不仅可以阅读到最新军事资讯,随时参与精彩话题讨论,还可以在线阅 ...
- android学习笔记26——Activity
Activity ==> android中四大组件:Activity.Service.BroadcastReceiver.ContentProvider Activity组件用于对用户呈现操作界 ...
- 战胜忧虑<4>——让平均概率来替你分忧
让平均概率来替你分忧. 我们可以根据事情发生的平均率来评估我们的忧虑究竟值不值,如此一来,我想你和我应该可以去除99%的忧虑. 故事 我从小生长在密苏里州的一个农场,有一天,正帮妈妈采摘樱桃的时候,我 ...
- python正则表达式的学习记录
match和findall的区别以及有括号和无括号的区别 strvar = "hello\n\nworld" find_re = re.compile("hello[.| ...