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. ReentrantLock 相关学习笔记

    ReentrantLock 相关学习笔记 标签(空格分隔): Java多线程 Java接口Lock有三个实现类:ReentrantLock.ReentrantReadWriteLock.ReadLoc ...

  2. poj 1654(利用叉积求面积)

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17937   Accepted: 4957 Description ...

  3. Remove @Override annotation错误提示

    因为对于JDK5.0/1.5版本来说,@Override annotation只能用与对超类的方法重写上, 而不能用在对接口方法的实现方法上. 解决的方法是把JDK改为1.6的或动手把注释@Overr ...

  4. C# axWindowsMediaPlayer制作播放器

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  5. Luis创建与发布

    首先打开网址https://www.luis.ai,打开后,需要使用你的微软帐户或是公司账户登录至Luis 登陆进入至网站后,会自动显示你的应用,在这里你可以修改和删除你之前已经创建过的应用,如果之前 ...

  6. POJ 2492 A Bug's Life【并查集高级应用+类似食物链】

    Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...

  7. scrapy详细数据流走向(个人总结)

    直接从数据流的角度来说比较容易理解: ·1.Spider创建一个初识url请求,把这个请求通过Engine转给Scheduler调度模块.然后Scheduler向Engine提供一个请求(这个请求是一 ...

  8. Diamond Collector (动态规划)

    问题 I: Diamond Collector 时间限制: 1 Sec  内存限制: 64 MB提交: 22  解决: 7[提交][状态][讨论版] 题目描述 Bessie the cow, alwa ...

  9. VisualVM远程JVM

    Tomcat配置 进入TOMCAT_HOME/bin目录 打开catalina.sh文件,加入如下信息: JAVA_OPTS="$JAVA_OPTS -Djava.rmi.server.ho ...

  10. 小程序使用npm模块(引入第三方UI),报错的多种解决办法。

    前言引入第三方模块时,我遇到了很多坑. 首先是微信.第三方模块的文档描述不清楚.其次.搜索到的博客,大部分是抄的文档 / 相互转载抄袭.作用有限. 于是,我自己做了各种条件下的测试.解决各种情况的引入 ...