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 <iostream>
using namespace std;

int main( )
{
    int num;
    int arr[1001];
    while(cin>>num)
    {
        int i,temp,counter=0;
        for(i=0;i<1001;i++)
            arr[i]=0;
        for(i=0;i<num;i++)
        {
            cin>>temp;
            arr[temp]++;
        }
        for(i=1;i<=1000;i++)
        {
            for(temp=1;temp<=1000;temp++)
            {
                if(arr[temp]!=0)
                {
                    arr[temp]--;
                    break;
                }
            }
            for(temp++;temp<=1000;temp++)
            {
                if(arr[temp]!=0)
                {
                    arr[temp]--;
                    counter++;
                }
            }
        }
        cout<<counter<<endl;
    }

    return 0;
}

  

 

Who's in the Middle的更多相关文章

  1. 代码的坏味道(21)——中间人(Middle Man)

    坏味道--中间人(Middle Man) 特征 如果一个类的作用仅仅是指向另一个类的委托,为什么要存在呢? 问题原因 对象的基本特征之一就是封装:对外部世界隐藏其内部细节.封装往往伴随委托.但是人们可 ...

  2. 【BZOJ-2653】middle 可持久化线段树 + 二分

    2653: middle Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 1298  Solved: 734[Submit][Status][Discu ...

  3. 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 ...

  4. [LintCode] Delete Node in the Middle of Singly Linked List 在单链表的中间删除节点

    Implement an algorithm to delete a node in the middle of a singly linked list, given only access to ...

  5. vertical-align:middle

    img style="vertical-align:middle;" src="<%=basePath%>/images/ckpy.png" > ...

  6. 【leetcode】Sort List (middle)

    Sort a linked list in O(n log n) time using constant space complexity. 思路: 用归并排序.设输入链表为S,则先将其拆分为前半部分 ...

  7. 【leetcode】Reorder List (middle)

    Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do thi ...

  8. 【leetcode】Number of Islands(middle)

    Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...

  9. 运用vertical:middle 使得元素垂直居中

    我要垂直居中我要垂直居中我要垂直居中我要垂直居中我要垂直居中垂直居中垂直居中垂直居中中垂直居中垂直居中   <!-- 第一步:主题元素display:inline-block;第二步:插入辅助元 ...

  10. Who's in the Middle 分类: POJ 2015-06-12 19:45 11人阅读 评论(0) 收藏

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

随机推荐

  1. HTML5学习指导路线

    HTML5是现在热门的技术,经过8年的艰苦努力,该标准规范终于制定完成,在这里为想要学习HTML5初级程序员详细划分一下学习内容和步骤,让大家清楚的知道HTML5需要学什么?能够快速掌握HTML5开发 ...

  2. c#使用PortableDeviceApiLib读取便携式设备(WPD:Windows Portable Devices)信息

    相关名词解释: WPD( Windows Portable Devices) 译作Windows 便携设备 (WPD) 是一种驱动程序技术,可支持广泛的可移动设备,比如移动电话.数码相机和便携媒体播放 ...

  3. Less注释语法

    Less注释语法 适当的注释是保证代码可读性的必要手段,Less支持两种类型的注释:多行注释和单行注释. 1)形如 /* */ 的多行注释.如: /* Hello, I'm a CSS-style c ...

  4. selenium 使用xpath定位不到

    <button id="" class="btn btn-some" type="submit"> <i class=&q ...

  5. 基于ESXI6.5的服务器基本配置(HP DL388 Gen 9)

    最近一段时间由于做毕业设计的原因,一直处于忙碌状态,刚做完毕业设计,导师处于项目的原因,买了一台惠普服务器(人民币1.7万),服务器自带的内存仅有16 G,硬盘也就只有600G,而且磁盘还做了raid ...

  6. 垃圾陷阱洛谷dp

    题目描述 卡门――农夫约翰极其珍视的一条Holsteins奶牛――已经落了到“垃圾井”中.“垃圾井”是农夫们扔垃圾的地方,它的深度为D(2<=D<=100)英尺. 卡门想把垃圾堆起来,等到 ...

  7. Solr6.5.0配置solrcore图文详解

    准备环境: solr6.5.0安装完成 jdk1.8 solrhome配置成功 详情:

  8. 走近Java

    学习Java需要了解必要的Java历史,不要觉得Java历史对学习Java编程没有任何帮助.在任何时候,了解一门语言的历史都能帮助更好地理解这门语言的精髓.以前在学习语文时,在分析一篇文章,通常会通过 ...

  9. 一个看起来不像中年人的中年人,带着两个初出茅庐的小伙子儿,用git管理项目代码的进击之路

    一个中年人的孤独前行 我们这一代人,是上个世纪的人,活在当下,已然成为社会上的中流砥柱. 80年代生人,遥望我们的父辈,均是5.60年代的人,迟迟暮年,夕夕老矣.而我们,正当年,却又时光飞逝,很快便要 ...

  10. day4、Linux基础题目

    第一题 我想在/data/da 目录下面创建 一个 da.txt 文件 [root@ll ~]# cd /data/oldboyedu -bash: cd: /data/oldboyedu: No s ...