题目描述

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. LeetCode OJ 78. Subsets

    Given a set of distinct integers, nums, return all possible subsets. Note: Elements in a subset must ...

  2. [kuangbin带你飞]专题四 最短路练习 POJ 2253 Frogger

    求第一个点到第二个点的所有通路上最长的边 dijkstra的变形 每次松弛的是每条边通路上的的最长的边 WA了好几次是因为用了%lf 改成%f就过了…… /* ******************** ...

  3. amazeui 后台模板

    <!doctype html> <html class="no-js"> <head> <meta charset="utf-8 ...

  4. layoutSubview触发时机

    layoutSubviews在以下情况下会被调用: 1.init初始化不会触发layoutSubviews 2.addSubview会触发layoutSubviews 3.设置view的Frame会触 ...

  5. 获取Camera 支持视频的尺寸

    <uses-permission android:name="android.permission.CAMERA" > </uses-permission> ...

  6. CSS的基本概念

    <!--CSS 一.概念:CSS的全称是Cascading Style Sheets,层叠样式表,用来控制HTML标签样式,在美化网页中起到非常重要的作用 CSS的编写格式是键值对形式的,比如 ...

  7. 2.3 DHC REST

    DHC REST也是Chrome浏览器的插件,可以在Chrome应用商店安装下载,主要用来模拟HTTP客户端发送测试数据到服务器.HTTP Get请求在开发中比较常用.

  8. perl中的pack与unpack

    这个pack, unpack在 "perl语言编程" 有介绍 看起来很复杂 #把一个字符串转为十六进制格式 my $source = 'abcd'; unpack('H*', $s ...

  9. HDU 5933/思维

    题目链接[http://acm.hdu.edu.cn/showproblem.php?pid=5933]; 题意: 给出n堆物品,问能不能分成K个数量相等的堆,如果能分,则最少次数是多少.分的规则为: ...

  10. 多工段查询存放到DataTable到List<DataTable>集合在C#里面做汇总

    private void btnQuery_Click(object sender, EventArgs e) { if (cboxFactory.Text=="") { Mess ...