题目描述

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. MVC5 Entity Framework学习之创建复杂的数据模型

    目录(?)[-] 使用属性来自定义数据模型 DataType属性 StringLength属性 Column 属性 完成对Student实体的更改 Required 属性 Display 属性 Ful ...

  2. SqlParameter关于Like的传参数无效问题

    正确的写法(简洁版) private void GetHandleData(string strKeyWord1, string strKeyWord2, string strKeyWord3) { ...

  3. SASL - 简单认证和安全层

    转自:http://blog.csdn.net/id19870510/article/details/8232509 SASL - 简单认证和安全层 SASL是一种用来扩充C/S模式验证能力的机制认证 ...

  4. Python字符串连接方式

    python中有很多字符串连接方式,总结一下: 1 最原始的字符串连接方式:str1 + str22 python 新字符串连接语法:str1, str23 奇怪的字符串方式:str1 str24 % ...

  5. php中文乱码问题分析及解决办法

    中文乱码问题产生的原因,主要就是字符编码设置问题:             首先,mysql数据库安装的时候字符编码要选择正确,最好选择utf-8比较保险.如果安装时没有设置正确,找到mysql的安装 ...

  6. Javaweb 第4 天xml 课程

    XML课程 今日大纲 ● XML概念 ● XML基本语法 ● XML约束 ● dom4j技术 ● xpath技术 ******************************************* ...

  7. /etc/fstab 文件解释

    /etc/fstab 文件解释 文件fstab包含了你的电脑上的存储设备及其文件系统的信息.它是决定一个硬盘(分区)被怎样使用或者说整合到整个系统中的唯一文件. 这个文件的全路径是/etc/fstab ...

  8. List-----Array

    1.Definition Arry数组是一种连续储存的List 储存方式:将线性表中的元素一次储存在连续的储存空间中. Computer's logical structure: 逻辑位置上相邻的元素 ...

  9. shell脚本学习(二)

    4.cat命令 1)  cat -s    摆脱多余的空白行 2)  cat -T    将制表符显示为^I 3)  cat -n    显示行号 4) cat -b    跳过空白行,然后显示行号 ...

  10. sql server基础学习之引号

    create table #(code varchar(20),value int)declare @sql varchar(200) set @sql='insert into # select ' ...