acm_problem_1016
2016-04-01 23:49
302 查看
题目描述:
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
* 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.
[align=left]Output[/align]
* Line 1: A single integer that is the median milk output.
[align=left]Sample Input[/align]
[align=left]Sample Output[/align]
大意:就是输入n个数,n为单数,求中位数。。
代码:
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int N,i,b,s[10001];
while(cin>>N)
{
if(N%2==1)
{
for(i=1;i<=N;i++)
{
cin>>s[i];
}
sort(s,s+N+1);
b=(N+1)/2;
cout<<s[b]<<endl;
}
}
}
感想:一个sort排序就可以了。。
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
* 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.
[align=left]Output[/align]
* Line 1: A single integer that is the median milk output.
[align=left]Sample Input[/align]
5 2 4 1 3 5
[align=left]Sample Output[/align]
3
大意:就是输入n个数,n为单数,求中位数。。
代码:
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int N,i,b,s[10001];
while(cin>>N)
{
if(N%2==1)
{
for(i=1;i<=N;i++)
{
cin>>s[i];
}
sort(s,s+N+1);
b=(N+1)/2;
cout<<s[b]<<endl;
}
}
}
感想:一个sort排序就可以了。。
相关文章推荐
- Android Volley完全解析
- Atitit.css 规范 bem 项目中 CSS 的组织和管理
- 蓝桥杯 错误票据
- Atitit.css 规范 bem 项目中 CSS 的组织和管理
- 在deepin上跑BOINC的一点经验总结
- DES算法的matlab实现
- 继承关系的初始化方法重写
- 继承关系的初始化方法重写
- 1014-O
- tomcat+myeclipse配置
- Atitit.css 规范 bem 项目中 CSS 的组织和管理
- ARM体系结构
- 文章标题
- 网络流与费用流(上)网络流
- C++混合编程之idlcpp教程Python篇(4)
- Android Studio 使用AIDL
- 个人网站搭建第一天
- css3入门笔记
- unity发布自定义分辨率
- Word Reversal