poj 2388 Who's in the Middle
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 31149 | Accepted: 18073 |
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
#include<stdio.h>
#include<algorithm>
using namespace std; int cmp(int x,int y)
{
if(x<y) return 1;
else return 0;
} int main ()
{
int n,t,i,j;
int a[1000005];
while (~scanf("%d",&n))
{
for(i=0;i<n;i++)
scanf("%d",&a[i]); sort(a,a+n,cmp);
if(n%2==0) t=(n/2)-1;
else t=n/2;
printf("%d\n",a[t]);
}
return 0;
}
poj 2388 Who's in the Middle的更多相关文章
- 2388 Who's in the Middle(简单排序)
训练计划的第一个问题,首先从水问题开始:排序的数组,中间数则输出. http://poj.org/problem?id=2388 冒泡排序: #include <iostream> usi ...
- 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: 31015 Accepted: 1 ...
- 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
点击打开链接 Who's in the Middle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28324 Acce ...
- POJ 2388 Who's in the Middle (快速选择算法:O(N)求数列第K大)
[题意]求数列中间项. ---这里可以扩展到数列第K项. 第一次做的时候直接排序水过了= =--这一次回头来学O(N)的快速选择算法. 快速选择算法基于快速排序的过程,每个阶段我们选择一个数为基准,并 ...
- Who's in the Middle - poj 2388 (快速排序寻找中位数)
题意; 寻找中位数 利用快速排序来寻找中位数. #include <iostream> using namespace std; int N; ]; int Median(int left ...
- 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(排序)
http://poj.org/problem?id=2388 题意:就N个数的中位数. 思路:用快排就行了.但我没用快排,我自己写了一个堆来做这个题.主要还是因为堆不怎么会,这个拿来练练手. #inc ...
随机推荐
- HDU 4119Isabella's Message2011成都现场赛I题(字符串模拟)
Isabella's Message Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- Java当中的运算符
一.关于Java当中运算符的分类 算术运算符:+,-,*,/.%(是取余运算符读莫).++.-- 关系运算符:>.<.>=.<=.!=(不等).==(等于) 布尔运算符:!(非 ...
- LINUX增加并管理用户
使用groupadd命令增加新的用户组 使用useradd命令增加新用户: useradd -s /bin/bash -d /home/XXX -g group username 使用passwd修改 ...
- objectivc-c---block
基本格式: returnType (^blockName[num])(paramList|void) = ^returnType(paramList|void){block Body}; 标红部分可根 ...
- QT-Demo-Colck-01
QT += widgets QT += core HEADERS += \ mainwindow.h SOURCES += \ mainwindow.cpp \ main.cpp #ifndef MA ...
- jQuery中对未来的元素绑定事件
对未来的元素绑定事件不能用bind, 1.可以用live代替,但是要注意jquery的版本,根据官方文档,从1.7开始就不推荐live和delegate了,1.9里就去掉live了. 2.推荐用on代 ...
- MVC 4.0 Razor模板引擎 @Html.RenderPartial 与 @Html.RenderAction 区别
近来在学习MVC 4.0,设置布局全局网页的页脚,使用了Razor语法 @{ Html.RenderPartial("Footer", Model.FooterData); } 但 ...
- spi ssp
SSP(Synchronous Serial Port 同步串行口)某些微处理器所含有的一个通信模块(或支持的通信模式),用来和外围串行部件或其他微处理器进行通信,这些外围部件可以是串行E2PROM. ...
- linux系统时间和硬件时钟问题(date和hwclock)
http://blog.chinaunix.net/uid-182041-id-3464524.html http://blog.csdn.net/duyiwuer2009/article/detai ...
- cf C. Find Maximum
http://codeforces.com/contest/353/problem/C 先预处理前i个数的和,然后找到第一个出现的1,然后变成0后的和与目前的和比较,如果大就更新. #include ...