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. iOS开发之多媒体API

    播放视频 视频文件介绍 视频格式可以分为适合本地播放的本地影像视频和适合在网络中播放的网络流媒体影像视频两大类.尽管后者在播放的稳定性和播放画面质量上可能没有前者 优秀,但网络流媒体影像视频的广泛传播 ...

  2. cocos2d-x v3.2 FlappyBird 各个类对象详细代码分析(7)

    今天我们介绍最后两个类 GameOverLayer类 GameLayer类 GameLayer类是整个游戏中最重要的类,由于是整个游戏的中央系统,控制着各个类(层)之间的交互,这个类中实现了猪脚小鸟和 ...

  3. c#中从string数组转换到int数组

    以前一直有一个数组之间转换的东西,可是忘记了,今天也是找了好久也没有解决,最后用这种方法解决了,分享给大家. " }; int[] output = Array.ConvertAll< ...

  4. Java基础知识强化43:StringBuffer类之StringBuffer和String的相互转化

    1. String和StringBuffer的相互转换 思想是:A-----B的转换,我们把A转换为B,其实是为了使用B的功能:B-----A的转换,我们可能的结果是A类型,所以还要转换回来 2. 案 ...

  5. VMware Virtual Machine安装报错解决1

    安装完VMware virtual machine 后,再进行 "create a new virtual machine"最后点击"Finish"时,报如下错 ...

  6. WPF之Binding的使用

    引出: 在WPF中Binding可以比作数据的桥梁,桥梁的两端分别是Binding的源(Source)和目标(Target).一般情况下,Binding源是逻辑层对象,Binding目标是UI层的控件 ...

  7. 关于获得本机Mac Address的方法

    网络上有讲获得Mac address的方法有如下: 1. 发送ARP命令,利用返回的Mac Address缓冲区得到 2. 用NetworkInterface.GetAllNetworkInterfa ...

  8. 新Android学习计划

    最近,在学习Android Design Support Library提供的新控件过程中,我感受到了原来的学习方式的缺点: 学习内容过于随意,在工作过程中碰到的新问题都想去掌握,心血来潮就想写一篇相 ...

  9. C# 解析嵌套的json文件.

    概述 今天我同学问我如何转换json文件,没处理过,网上搜了一下,json转excel的很少,反过来倒是有许多人写了工具. json文件的结构大致是这样的: {, , }, , "type& ...

  10. arcgis server manager - An error has occured on the server. For details please check the Event (Application) log on the web.

    当登陆 Arcgis Server Manager的时候,点击 "Services" 中的选项"Manage Services",就报错: An error h ...