练习一1016
来源:互联网 发布:网络编程 什么语言 编辑:程序博客网 时间:2024/05/22 03:27
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 <br> <br>* 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
Statistic | Submit | Back
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 <br> <br>* 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
Statistic | Submit | Back
思路:
又是一道非常简单的题目,先排序再找出中间那个即可。
代码:
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int a[10000],m=0,n;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
cout<<a[(n-1)/2]<<endl;
return 0;
}
#include<algorithm>
using namespace std;
int main()
{
int a[10000],m=0,n;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
cout<<a[(n-1)/2]<<endl;
return 0;
}
1 0
- 练习一1016
- 练习一
- 练习一
- 练习一
- 练习一
- 2016SDAU课程练习一1016Q
- 2016SDAU课程练习一1016
- 课程练习一 Problem Q id 1016
- 2016SDAU课程练习一1016
- access+asp 练习一
- 数据库练习一答案
- C++基础练习一
- XML练习(一)
- javascript练习(一)
- jQuery练习(一)
- 软件测试练习一
- 听力练习一
- c++练习一
- 利用tomcat redis 实现session共享
- POJ 1064 Cable master(二分查找 求近似解)
- position定位
- 数据结构课设 银行排队问题之单队列多窗口服务
- Boost编译和配置教程(Win10+VS2013+Boost1.60.0)
- 练习一1016
- C#——判断一个数是奇偶性
- 八皇后问题(python版理解)
- 原生代码加载网络图片和Volley和Picasso的简单介绍和优缺点对比
- mybatis开始第1天
- PHP之PDO
- Ajax基础
- 关于stm32 RTC配置相关说明
- TCP之RST发送场景