题目描述

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. 推荐学习c语言的几个开源项目

    1. Webbench Webbench是一个在linux下使用的非常简单的网站压测工具.它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的性能,最多可以模拟3万个并发连 ...

  2. 使用Cookie来统计浏览次数,当天重复刷新不增加

    这是一种不严谨的做法,在浏览量不是很重要的时候可以使用 var oldCookie = Request.Cookies["newsCookie"]; if (oldCookie = ...

  3. hdu 1210 Eddy's 洗牌问题

    Problem Description Eddy是个ACMer,他不仅喜欢做ACM题,而且对于纸牌也有一定的研究,他在无聊时研究发现,如果他有2N张牌,编号为1,2,3..n,n+1,..2n.这也是 ...

  4. $pull

    $pull 删除所有匹配的文档,不仅仅只是删除一个. db.test.insert( {"todo":["dishes","laundry" ...

  5. MySQL binlog 查看信息

    1)按时间筛选 mysqlbinlog --start-datetime="2009-09-14 0:20:00" --stop-datetim="2009-09-15 ...

  6. offset()值不准问题

    本来应该只需获取含图片的div的offset(),然后将标签div的坐标设置好即可,但是不知为何越靠后的div的offset().top越不正常,跟标准值偏离的越来越大. 即使你在$(document ...

  7. css3字体

    1.定义个性化字体 @font-face{ font-family:字体名字; src:字体地址,可以多写几个用逗号隔开兼容浏览器 } div{ font-family:字体名字/*使用字体*/ } ...

  8. HDU 3416 Marriage Match IV

    最短路+最大流 #include<cstdio> #include<cstring> #include<string> #include<cmath> ...

  9. js 交换表单中值

    <html> <head> <meta charset="utf-8" /> <script type="text/javasc ...

  10. windows7安装oracle 10g

    1.出现如下错误 解决办法: ①确保你有该文件夹的完全控制权.文件夹点右键->属性->安全->高级->所有者->改为自己->编辑自己的权限为完全控制. ②将setu ...