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

  1. 5
  2. 2
  3. 4
  4. 1
  5. 3
  6. 5

Sample Output

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

一道排序水题。

  1. #include<cstdio>
  2. #include<stdlib.h>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<iostream>
  6.  
  7. using namespace std;
  8.  
  9. const int M = 10000 + 5;
  10. int cow[M];
  11.  
  12. int main()
  13. {
  14. int n;
  15. while(scanf("%d", &n)!=EOF)
  16. {
  17. memset(cow, 0, sizeof(cow));
  18. for(int i=0; i<n; i++)
  19. scanf("%d", &cow[i]);
  20. sort(cow, cow+n);
  21. printf("%d\n", cow[n/2]);
  22. }
  23.  
  24. return 0;
  25. }

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. c# tcplistener 与 client通信 服务端 今天写一下

    using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Lin ...

  2. [poj_3469]多核CPU

    Sample Input 3 1 1 10 2 10 10 3 2 3 1000 Sample Output 13 最小割,把模块看做点,建源点s和汇点t,以下(a,b,c)表示从a向b连一条容量为c ...

  3. [leetcode]Convert Sorted Array to Binary Search Tre

    排好序的... 中间是root , root左边是left,root右边是right 递归建树. /** * Definition for binary tree * struct TreeNode ...

  4. js常用函数总结

    字符串函数 indexOf 返回字符串中一个子串第一处出现的索引(从左到右搜索).如果没有匹配项,返回 -1 . var index1 = a.indexOf("l"); //in ...

  5. IE浏览器对虚拟主机配置域名的问题

    之前一直搞不明白web开发做本地调试的时候IE浏览器老是无法登陆,而谷歌和其他内核浏览器能正常登陆的问题,后来发现IE浏览器对WEB服务器配置的虚拟主机域名规则是不能包含这个'_'下划线符号的,否则会 ...

  6. redis集群PHP解决方案

    Redis3.2.4 Cluster集群搭建 服务器环境:192.168.3.229192.168.3.193每台服务器搭建3个节点,组成3个主节点,3个从节点的redis集群. 注意:防火墙一定要开 ...

  7. 利用JavaScript打印出Fibonacci数(不使用全局变量)

    从汤姆大叔的博客里看到了6个基础题目:本篇是第4题 - 利用JavaScript打印出Fibonacci数(不使用全局变量) 解题关键: 1.Fibonacci数列的规律 2.递归 解点1:Fibon ...

  8. Python的功能模块[0] -> wmi -> 获取 Windows 内部信息

    wmi模块 / wmi Module WMI (Windows Management Instrumentation) 模块可用于获取 Windows 内部信息.该模块需要 win32com 的支持, ...

  9. HDU 6396 Swordsman --------2018 Multi-University Training Contest 7 (模拟+读入挂)

    原题地址: 打怪升级 一开始有N个怪物:主角有K个能力:只有K个能力都击败怪物才能斩杀怪物并获得K个能力的增值:问最多能杀几个怪物: 做法: 用优先队列把怪物能力装进去:能力小放前面: 最重要的是数据 ...

  10. 树链剖分【p2590】[ZJOI2008]树的统计

    Description 一棵树上有n个节点,编号分别为1到n,每个节点都有一个权值w. 我们将以下面的形式来要求你对这棵树完成一些操作: I. CHANGE u t : 把结点u的权值改为t II. ...