SDAU课程练习--problemQ(1016)
题目描述
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代码
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[10000];
int main()
{
//freopen("date.in", "r", stdin);
//freopen("date.out", "w", stdout);
int N;
while (~scanf("%d", &N))
{
//memset(a, 0, 10000 * sizeof(int));
for(int i = 0; i < N; i++)
{
cin>>a[i];
}
sort(a, a + N);
cout << a[(N + 1) / 2-1];
}
}
SDAU课程练习--problemQ(1016)的更多相关文章
- SDAU课程练习--problemG(1006)
题目描述 Problem Description The highest building in our city has only one elevator. A request list is m ...
- SDAU课程练习--problemO(1014)
题目描述 Before bridges were common, ferries were used to transport cars across rivers. River ferries, u ...
- SDAU课程练习--problemB(1001)
题目描述 There is a pile of n wooden sticks. The length and weight of each stick are known in advance. T ...
- SDAU课程练习--problemA(1000)
题目描述 The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape i ...
- SDAU课程练习--problemC
题目描述 Here is a famous story in Chinese history. "That was about 2300 years ago. General Tian Ji ...
- SDAU课程练习--problemE
problemE 题目描述 "今年暑假不AC?" "是的." "那你干什么呢?" "看世界杯呀,笨蛋!" "@ ...
- sicily 1016. 排队接水--课程作业
1016. 排队接水 Time Limi ...
- 20165319 2017-2018-2《Java程序设计》课程总结
一.每周作业链接汇总 预备作业一:我期望的师生关系 20165319 我所期望的师生关系 预备作业二:学习基础和C语言基础调查 20165319 学习基础和C语言基础调查 摘要: 技能学习经验 c语言 ...
- .NET 提升教育 第一期:VIP 付费课程培训通知!
为响应 @当年在远方 同学的建议,在年前尝试进行一次付费的VIP培训. 培训的课件:点击下载培训周期:10个课程左右,每晚1个半小时培训价格:1000元/人.报名方式:有意向的请加QQ群:路过秋天.N ...
随机推荐
- 有关下行HARQ的一切
1. 对于下行HARQ,有几种类型的下行传输需要UE反馈ACK/NACK 动态调度的下行传输:UE收到一个使用C-RNTI或TC-RNTI(对应随机接入过程中的Msg4)加扰的PDCCH和PDSCH, ...
- ZIP文件解压
public class DZip { /// <summary> /// 压缩为ZIP文件 /// </summary> public void Zip(string dir ...
- c/c++常用的几个关键字总结
一.volatile volatile提醒编译器它后面所定义的变量随时都有可能改变,因此编译后的程序每次需要存储或读取这个变量的时候,都会直接从变量地址中读取数据.如果没有volatile关键字,则编 ...
- redis数据类型:lists
redis的list类型其实就是一个每个子元素都是string类型的双向链表. 我们可以通过push,pop操作从链表的头部或者尾部添加删除元素,这样list即可以作为 栈,又可以作为队列. lpus ...
- Keyboard Test Utility v1.0.1.0 电脑键盘测试软件绿色版
软件名称: 电脑键盘测试软件绿色版软件语言: 简体中文授权方式: 免费软件运行环境: Win8 / Win7 / Vista / WinXP软件大小: 917KB图片预览: 软件简介:Keyboard ...
- Announcement
本来是习惯把每天的内容写在一个txt里. 似乎不符合要求.无论格式还是内容.于是转战blog. 事实上.有专业课学习加上马上考四级以及下学期可能的专业调整.此学期时间紧张. 能完成日常作业并掌握周课内 ...
- 表单属性问题readonly、disabled、checked,prop的使用
获取在匹配的元素集中的第一个元素的属性值. 随着一些内置属性的DOM元素或window对象,如果试图将删除该属性,浏览器可能会产生错误.jQuery第一次分配undefined值的属性,而忽略了浏览器 ...
- MyBatis 多表联合查询,字段重复的解决方法
MyBatis 多表联合查询,两张表中字段重复时,在配置文件中,sql语句联合查询时使用字段别名,resultMap中对应的column属性使用相应的别名: <resultMap type=&q ...
- 浅谈C/C++结构体内存分配问题
.wiz-todo, .wiz-todo-img {width: 16px; height: 16px; cursor: default; padding: 0 10px 0 2px; vertica ...
- IP子网掩码格式转换
def exchange_maskint(mask_int): bin_arr = [' for i in range(32)] for i in range(mask_int): bin_arr[i ...