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. 常用的find命令

    find命令 find [路径名] –name/-size/-perm find [路径名] –name “*p” 在路径搜索p结尾的文件夹及文件 find [路径名] –name “[ab]*” 在 ...

  2. ie_placeholder最佳兼容方案

    https://gitee.com/hustcc/placeholder.js巧妙的使用了canvas.toDataURL(),动态生成了一个背景图,可以作为兼容IE9-的placeholder方案. ...

  3. Delphi读写二进制文件

    http://www.cnblogs.com/hnxxcxg/p/3691742.html 二进制文件(也叫类型文件),二进制文件是由一批同一类型的数据组成的一个数据序列,就是说一个具体的二进制文件只 ...

  4. AC日记——Dynamic Problem Scoring codeforces 807d

    Dynamic Problem Scoring 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <io ...

  5. PHP开发经常遇到的几个错误

    错误1:foreach循环后留下悬挂指针 在foreach循环中,如果我们需要更改迭代的元素或是为了提高效率,运用引用是一个好办法: $arr = array(1,2,3,4); foreach($a ...

  6. Chief Technology Officer

    转自地址:http://www.swoole.com/News/76.html 1)错误都是自上而下 当事情出现混乱的时候,人们总是寻求寄托于Process的制定,很多的管理者,觉察到事情的失控,却不 ...

  7. 训练指南 UVALive - 4080(最短路Dijkstra + 边修改 + 最短路树)

    layout: post title: 训练指南 UVALive - 4080(最短路Dijkstra + 边修改 + 最短路树) author: "luowentaoaa" ca ...

  8. mysql使用default来设置字段的默认值

    mysql创建表时,我们可以使用default来设置表字段的默认值,这样当向表中插入或添加数据时,如果没有为此字段设置任何值,则使用default默认值来填充该字段的值 在使用create table ...

  9. 【BZOJ 2333 】[SCOI2011]棘手的操作(离线+线段树|可并堆-左偏树)

    2333: [SCOI2011]棘手的操作 Description 有N个节点,标号从1到N,这N个节点一开始相互不连通.第i个节点的初始权值为a[i],接下来有如下一些操作: U x y: 加一条边 ...

  10. DNS无响应

    无语,运行某某大品牌的杀毒软件后,无法上网,window检查后是DNS服务器无响应. 开始>运行>输入"netsh winsock reset"  然后重启电脑. pi ...