2016SDAU课程练习一1016
来源:互联网 发布:数控车床编程 编辑:程序博客网 时间:2024/04/29 18:31
Problem Description
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
题意:平均值啦
思路:排序取中间的
感想:应该是最简单的吧,但是每次博客写完粘代码就手残刷新了。。刷新。。。刷新。。。。这题有毒。。。
AC代码:
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<math.h>
#include<string.h>
#include<sstream>
#include<stdio.h>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
using namespace std;
int main()
{
int n,i,a,b,s;
vector<int>v;
while(cin>>n)
{
for(i=0;i<n;i++)
{
cin>>a;
v.push_back(a);
}
sort(v.begin(),v.end());
if(n%2!=0)
{
b=(n+1)/2;
s=v[b-1];
}
else
{
b=n/2;
s=(v[b-1]+v[b])/2;
}
cout<<s<<endl;
}
return 0;
}
- 2016SDAU课程练习一1016Q
- 2016SDAU课程练习一1016
- 2016SDAU课程练习一1016
- 2016sdau课程练习专题一 1016 problemQ
- 2016SDAU课程练习一1004
- 2016SDAU课程练习一1004 E
- 2016SDAU课程练习一1000
- 2016SDAU课程练习一Problem G
- 2016SDAU课程练习一1000A
- 2016SDAU课程练习一1006
- 2016SDAU课程练习一Problem E
- 2016SDAU课程练习一1001
- 2016SDAU课程练习一 1012
- 2016SDAU课程练习一 1006
- 2016SDAU课程练习一1005
- 2016SDAU课程练习一1012
- 2016SDAU课程练习一1000
- 2016SDAU课程练习一1001
- 1000. MyString Class
- ListView,ScrollView,RecyclerView被HorizontalScrollView嵌套,加载图片
- 第一范式
- linux idea14 maven 部署 tomcat. 遇到的问题
- VERY DEEP CONVOLUTIONAL NETWORKS FOR LARGE-SCALE IMAGE RECOGNITION
- 2016SDAU课程练习一1016
- 实例操作1
- java socket报文通信(三)java对象和xml格式文件的相互转换
- android studio svn版本控制详解
- css百事可乐
- IOS学习之iOS开发中用户密码应该保存在哪里
- 查找与排序之二分法查找篇(C语言实现)
- 采用认证方式连接mongodb
- 23种设计模式全解析