Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 31015   Accepted: 17991

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

Hint

INPUT DETAILS: 



Five cows with milk outputs of 1..5 



OUTPUT DETAILS: 



1 and 2 are below 3; 4 and 5 are above 3.

一道排序水题。

#include<cstdio>
#include<stdlib.h>
#include<cstring>
#include<algorithm>
#include<iostream> using namespace std; const int M = 10000 + 5;
int cow[M]; int main()
{
int n;
while(scanf("%d", &n)!=EOF)
{
memset(cow, 0, sizeof(cow));
for(int i=0; i<n; i++)
scanf("%d", &cow[i]);
sort(cow, cow+n);
printf("%d\n", cow[n/2]);
} return 0;
}

POJ 2388:Who&#39;s in the Middle的更多相关文章

  1. poj 2388 insert sorting

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

  2. POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)

    http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...

  3. POJ 3252:Round Numbers

    POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...

  4. Ultra-QuickSort 分类: POJ 排序 2015-08-03 15:39 2人阅读 评论(0) 收藏

    Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 48111   Accepted: 17549 ...

  5. POJ 2965:The Pilots Brothers&#39; refrigerator

    id=2965">The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  6. POJ 2388 Who's in the Middle (快速选择算法:O(N)求数列第K大)

    [题意]求数列中间项. ---这里可以扩展到数列第K项. 第一次做的时候直接排序水过了= =--这一次回头来学O(N)的快速选择算法. 快速选择算法基于快速排序的过程,每个阶段我们选择一个数为基准,并 ...

  7. poj 2388 Who&#39;s in the Middle

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

  8. POJ 2388 Who's in the Middle(水~奇数个数排序求中位数)

    题目链接:http://poj.org/problem?id=2388 题目大意: 奇数个数排序求中位数 解题思路:看代码吧! AC Code: #include<stdio.h> #in ...

  9. POJ 2388(排序)

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

随机推荐

  1. laravel 学习笔记 —— 神奇的服务容器

    转载自:https://www.insp.top/learn-laravel-container 容器,字面上理解就是装东西的东西.常见的变量.对象属性等都可以算是容器.一个容器能够装什么,全部取决于 ...

  2. eclipse 导出burpsuite插件包含第三方lib包

    第一步:右键项目点击export: 2.选择Runable JAR file: 点击Finish后会爆出一个错误(Jar export finished with problems. See deta ...

  3. (wifi)wifi移植之命令行调试driver和supplicant

    前言 小弟从事android wifi framework部分开发已经有一年的时间了,虽然感觉什么都没有学习到,但是回想起刚接手android wifi时候的那份无知,其实肚子里面还是有点东西的,本着 ...

  4. Mac下Lua环境搭建

    lua源文件下载安装 到官网安装了lua包,我安装的是 lua-5.3.1 解压之后,命令行cd进入到src目录下,输入make macosx 完成后cd ..到上一层目录, 输入sudo make ...

  5. c/c++中const用法总结

    1.修饰常量时: const int temp1;  //temp1为常量,不可变 int const temp2;  //temp2为常量,不可变 2.修饰指针时: 主要看const在*的前后,在前 ...

  6. 7.添加OpenStack计算服务

    添加计算服务 安装和配置控制器节点 创建数据库 mysql -uroot -ptoyo123 CREATE DATABASE nova; GRANT ALL PRIVILEGES ON nova.* ...

  7. (4) python--seaborn

    seaborn封装了matplotlib的一些风格,简单的介绍一下

  8. linux用户登录

    一.linux用户登录过程访问的文件 /etc/passwd---用户登录时,linux会先到这里查看用户Id.组Id.登录后的shell.用户工作目录 /etc/shadow(影)---linux在 ...

  9. 【原创】SSAS-引用维度与多数据源、多数据源视图引发分区错误

    背景: 最近有个项目,有32家分公司,集团总部需要取这个32家分公司数据做分析,由于每个分公司的数据都比较庞大,所以最终方案是每个分公司一个DW,在cube搭建过程中将每个公司数据作为一个分区数据的来 ...

  10. 正则表达式之Regex.Replace()用法

    正则表达式替换匹配到的字符串 string txt = "AAA12345678AAAA"; //匹配到的连续数字的前4位用*替换 string m =Regex.Replace( ...