题目描述

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

题目大意

十足的水题,排序后找出中位数即可

AC代码

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<algorithm>
  4. using namespace std;
  5. int a[10000];
  6. int main()
  7. {
  8. //freopen("date.in", "r", stdin);
  9. //freopen("date.out", "w", stdout);
  10. int N;
  11. while (~scanf("%d", &N))
  12. {
  13. //memset(a, 0, 10000 * sizeof(int));
  14. for(int i = 0; i < N; i++)
  15. {
  16. cin>>a[i];
  17. }
  18. sort(a, a + N);
  19. cout << a[(N + 1) / 2-1];
  20. }
  21. }

SDAU课程练习--problemQ(1016)的更多相关文章

  1. SDAU课程练习--problemG(1006)

    题目描述 Problem Description The highest building in our city has only one elevator. A request list is m ...

  2. SDAU课程练习--problemO(1014)

    题目描述 Before bridges were common, ferries were used to transport cars across rivers. River ferries, u ...

  3. SDAU课程练习--problemB(1001)

    题目描述 There is a pile of n wooden sticks. The length and weight of each stick are known in advance. T ...

  4. SDAU课程练习--problemA(1000)

    题目描述 The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape i ...

  5. SDAU课程练习--problemC

    题目描述 Here is a famous story in Chinese history. "That was about 2300 years ago. General Tian Ji ...

  6. SDAU课程练习--problemE

    problemE 题目描述 "今年暑假不AC?" "是的." "那你干什么呢?" "看世界杯呀,笨蛋!" "@ ...

  7. sicily 1016. 排队接水--课程作业

                                                                                    1016. 排队接水 Time Limi ...

  8. 20165319 2017-2018-2《Java程序设计》课程总结

    一.每周作业链接汇总 预备作业一:我期望的师生关系 20165319 我所期望的师生关系 预备作业二:学习基础和C语言基础调查 20165319 学习基础和C语言基础调查 摘要: 技能学习经验 c语言 ...

  9. .NET 提升教育 第一期:VIP 付费课程培训通知!

    为响应 @当年在远方 同学的建议,在年前尝试进行一次付费的VIP培训. 培训的课件:点击下载培训周期:10个课程左右,每晚1个半小时培训价格:1000元/人.报名方式:有意向的请加QQ群:路过秋天.N ...

随机推荐

  1. Java使用千分位并保留两位小数

    double d = 123456.789; DecimalFormat df = new DecimalFormat("#,##0.00"); System.out.printl ...

  2. erlang套接字

    Erlang的套接字可以有三种打开模式:主动(active).单次主动(active once)或被动(passive).这是通过在gen_tcp:connect(Address, Port, Opt ...

  3. A - Space Elevator(动态规划专项)

    A - Space Elevator Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  4. js怎么判断浏览器类型

    <script type=“text/javascript”> function isIE(){return navigator.appName.indexOf(“Microsoft In ...

  5. 借助nginx搭建反向代理服务器小例

    1 反向代理: 反向代理(Reverse Proxy)方式是指以代理服务器接收internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接 ...

  6. GetWindowRect和GetClientRect的异同

    由于项目需要,需要学习CGridCtrl控件的使用,测试控件时发现了一个问题,我无法将控件放在对话框的制定位置. 该问题的原因很容易发现,其实就是GetWindowRec()函数和GetClientR ...

  7. POJ 2239 Selecting Courses

    二分图的最大匹配.课程和时间可以看做二分图. #include<cstdio> #include<cstring> #include<cmath> #include ...

  8. 快速切换天财商龙门店后台.VB6.0

    名称:快速切换天财商龙门店后台 作者:landv 时间:2015年8月21日 功能:快速切换天财商龙门店后台 环境:VB6.0 注:懒的一行一行修改文件了,直接覆盖配置文件,Tcgem.ini 只能反 ...

  9. LeetCode OJ 292.Nim Gam148. Sort List

    Sort a linked list in O(n log n) time using constant space complexity. 排序问题是我们遇到的一个老问题,从大一开始我们就学习了各种 ...

  10. Git从远程库克隆

    上次我们讲了先有本地库,后有远程库,如何关联远程库. 现在,假设我们从零开始开发,那么最好的方式就是先创建远程库,然后从远程库克隆. 首先,登录GitHub,创建一个新的仓库,gitskill 创建过 ...