Who's in the Middle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 9411    Accepted Submission(s): 4538
Problem 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.
 
Source

水水水

#include <stdio.h>
#include <algorithm>
using std::sort;
#define maxn 10002 int arr[maxn]; int main()
{
int n, i;
while(scanf("%d", &n) == 1){
for(i = 0; i < n; ++i)
scanf("%d", &arr[i]);
sort(arr, arr + n);
printf("%d\n", arr[(n-1) >> 1]);
}
return 0;
}

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

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

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

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

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

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

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

  4. 02python程序设计基础——字符串

    字符串方法 format 1.替换字段名 在最简单的情况下,只需向 format 提供要设置其格式的未命名参数,并在格式字符串中使用未命名字段.此时,将按顺序将字段和参数配对.你还可给参数指定名称,这 ...

  5. Who's in the Middle[HDU1157]

    Who's in the Middle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  6. 基于C#的BarCode 39实现

    一.39条码简介 39码是1974年发展出来的条码系统,是一种可供使用者双向扫瞄的分散式条码,也就是说相临两资料码之间,必须包含一个不具任何意义的空白(或细白,其逻辑值为0),且其具有支援文字的能力, ...

  7. 圣思源Java视频36节练习源码分享(自己的190+行代码对比老师的39行代码)

    题目: * 随机生成50个数字(整数),每个数字范围是[10,50],统计每个数字出现的次数 * 以及出现次数最多的数字与它的个数,最后将每个数字及其出现次数打印出来, * 如果某个数字出现次数为0, ...

  8. 剑指Offer:数组中出现次数超过一半的数字【39】

    剑指Offer:数组中出现次数超过一半的数字[39] 题目描述 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字.例如,输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}.由于这 ...

  9. 【转】39个让你受益的HTML5教程

    闲话少说,本文作者为大家收集了网上学习HTML5的资源,期望它们可以帮助大家更好地学习HTML5. 好人啊! 不过,作者原来说的40个只有39个,因为第5个和第8个是重复的. 原文在此! 1. 五分钟 ...

随机推荐

  1. Nginx网站根目录更改及导致403 forbidden的问题解决

    最近因为工作需要,要将Nginx网站根目录更改下,通过网上的一些教程更改后,但发现测试的时候一直提示403 forbidden错误,后台通过一个朋友的提示也解决了,所以现在将详细的步骤分享给大家,有需 ...

  2. rhel 6.5 yum源的配置

    https://blog.csdn.net/error_0_0_/article/details/54962199

  3. QTP自动化测试框架的基础知识

    1. 什么是自动化测试框架? 假定你有一个活,需要构建许多自动化测试用例来测试这个应用程序.当你对这个应用程序完成自动化测试后,你对自己创建脚本应该有什么期望吗?你难道不想要- 脚本应该按照预期的来执 ...

  4. 安装Team Services Agent Win7

    现状:项目现时使用的是Team Services,使用Team Services可以控制其中的一台Build Server,从Github提取代码,并在Build Server进入编译打包处理(son ...

  5. SQL 插入多行数据语句整理

     参考别人的,希望对大家有用. 1.只是插入简单的有限行数据时用: insert 要插入的表名(列名1,列名2,....) select '列名1需要的数据','列名2需要的数据',... union ...

  6. ANDROID NFC读M1卡

    <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.Cons ...

  7. Codeforces #447 Div2 D

    #447 Div2 D 题意 给一棵完全二叉树,每条边有权值为两点间的距离,每次询问 \(x, h\) ,从结点 \(x\) 出发到某一结点的最短路的距离 \(d\) 如果小于 \(h\) ,则答案加 ...

  8. 洛谷——P1586 四方定理

    P1586 四方定理 题目描述 四方定理是众所周知的:任意一个正整数nn,可以分解为不超过四个整数的平方和.例如:25=1^{2}+2^{2}+2^{2}+4^{2}25=12+22+22+42,当然 ...

  9. next_permutatio

    next_permutation的函数声明:#include  <algorithm> bool next_permutation( iterator start, iterator en ...

  10. DataNucleus(通过jpa和jdo接口访问多中数据源)

    DataNucleus主页:http://www.datanucleus.org/index.html 简介: DataNucleus项目为Java运行环境中的应用数据提供了管理,它提供了标准的接口( ...