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

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
#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&#39;s in the Middle的更多相关文章

  1. 2388 Who&#39;s in the Middle(简单排序)

    训练计划的第一个问题,首先从水问题开始:排序的数组,中间数则输出. http://poj.org/problem?id=2388 冒泡排序: #include <iostream> usi ...

  2. poj 2388 insert sorting

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

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

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

  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. Who's in the Middle - poj 2388 (快速排序寻找中位数)

    题意; 寻找中位数 利用快速排序来寻找中位数. #include <iostream> using namespace std; int N; ]; int Median(int left ...

  8. 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 ...

  9. POJ 2388(排序)

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

随机推荐

  1. Protobuf实现Android Socket通讯开发教程

    本节为您介绍Protobuf实现Android Socket通讯开发教程,因此,我们需要先了理一下protobuf 是什么? Protocol buffers是一种编码方法构造的一种有效而可扩展的格式 ...

  2. pwn学习之dl_resolve学习篇

    一:首先来了解一下linux下常见的攻击缓解机制: CANARY:(金丝雀值,指的是矿工曾利用金丝雀来确认是否有气体泄漏,如果金丝雀因为气体泄漏而中毒死亡,可以给矿工预警),类似于windows GS ...

  3. Word02-隐藏回车换行符

    Word文档中每次输入回车后,会显示一个换行标志符,影响页面显示效果. 如下图,换行符隐藏前后: 设置方法:(选项-->显示-->段落标记前面的√去掉即可)

  4. java基础之导入(Excel)2

    $(function(){ $("#linksCommonGrid").datagrid({ url:appPath+'/page/pageIndexMrgAct/queryPag ...

  5. Aspose.Cells for .NET 8.5.0 工具类

    基于 Aspose.Cells for .NET 8.5.0 工具类, Aspose.Cells for .NET 8.5.0 这个自己去CSDN下载里面有破解的,没有破解的导出excel的时候会(A ...

  6. c - 每位数字尾部加空格

    /* input:一个4位整数. output:每位整数后紧跟一个空格的字符串. */ char * insert(char *s) { int len = strlen(s); * len + ); ...

  7. [c#]asp.net开发微信公众平台(4)关注事件、用户记录、回复文本消息

    上一篇已经把所有消息封装且都各自有方法处理了,这篇从使用第一步——关注开始,  关注之后进行消息记录,同时回复文本消息给用户,关注方法:DoSub,另外新用户扫描带参数的二维码关注方法:DoCodeN ...

  8. MySQL 远程访问开启

    打开mysql客户端,直接运行以下命令:1.use mysql; 2.update user set host='%' where user='root'; 会报错:ERROR 1062 (23000 ...

  9. ios内存详解

    IOS以及Mac os都是基于Unix/linux改造出来的,而在内存管理方面也沿用了Unix/Linux的内存管理机制. 下面主要说的是IOS系统,有很多比较喜欢捣鼓的吧友肯定自己清理过机器的内存, ...

  10. uva 105 - The Skyline Problem

    一.用数组储存该位置的最高点即可(图形的连续点离散化),注意左边界及右边界的情况: 注意:无论建筑物最左边是盖到哪里,你都得从1开始输出(输入输出都是integer,所以才能离散化): #includ ...