题意;
寻找中位数
利用快速排序来寻找中位数。
 #include <iostream>
using namespace std;
int N;
int op[];
int Median(int left,int right,int pos){
int l=left-,r=left;
int pirior=op[right];
for(int i=left;i<right;i++){
if(op[i]<pirior){
int temp=op[i];
op[i]=op[r];
op[r]=temp;
r++;
l++;
}
}
int t=op[right];
op[right]=op[r];
op[r]=t;
if(r==pos){
return op[r];
}else if(r<pos){
return Median(r+,right,pos);
}if(r>pos){
return Median(left,r-,pos);
} }
int main() {
cin>>N;
for(int i=;i<N;i++){
cin>>op[i];
}
int mid=Median(,N-,N/);
cout<<mid<<endl;
return ;
}
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 34962   Accepted: 20387

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

* 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

Hint

INPUT DETAILS:

Five cows with milk outputs of 1..5

OUTPUT DETAILS:

1 and 2 are below 3; 4 and 5 are above 3.

最新文章

  1. Xcode6新特性(1)-删除Main.storyboard
  2. C#实现K-MEDOIDS聚类算法
  3. js的forEach,for in , for of
  4. 安装swoole 扩展,在phpinfo中显示,但是php -m 中不显示的问题
  5. 使用J2SE API读取Properties文件的六种方法
  6. Oracle中的AS和IS
  7. 这是一个在Windows live 上实验的文章
  8. phpquery笔记
  9. hdu1728逃离迷宫 (利用最短路径思想+优先队列(BFS))
  10. Tian Ji -- The Horse Racin
  11. 局部内部类访问方法的参数和局部变量必须是final的
  12. [leetcode-557-Reverse Words in a String III]
  13. api_request.go
  14. SSM框架的sql中参数注入(#和$的区别)
  15. SQL Server OPTION (OPTIMIZE FOR UNKNOWN) 测试总结
  16. react中用pace.js
  17. PHP破解wifi密码(wifi万能钥匙的接口)
  18. unity3D OnTriggerEnter和OnCollisionEnter的区别
  19. iOS 项目国际化(多语言支持)
  20. webstorm批量查找,批量替换快捷键

热门文章

  1. 8、面向对象class
  2. SpringMVC学习记录(七)--拦截器的使用
  3. DELPHI MAKEWORD的用法
  4. 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:2.搭建环境-2.10.配置用户NTF服务
  5. C#之鼠标模拟技术
  6. webservice ssl双向认证配置
  7. [Angular] Angular Attribute Decorator - When to use it?
  8. 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-人机界面如何设置页面跳转
  9. UIScreenAdaptive
  10. Hadoop之词频统计小实验