您的位置:首页 > 其它

BZOJ1753: [Usaco2005 qua]Who's in the Middle

2017-07-21 14:14 471 查看

问n<=10000个点的中位数。

水题必有玄机!(然后浪费了半天在怎么O(n)求中位数并且最后放弃了)

1 #include<stdio.h>
2 #include<string.h>
3 #include<algorithm>
4 #include<cstdlib>
5 //#include<iostream>
6 using namespace std;
7
8 int n;
9 #define maxn 10011
10 int a[maxn];
11 int main()
12 {
13     scanf("%d",&n);
14     for (int i=1;i<=n;i++) scanf("%d",&a[i]);
15     sort(a+1,a+1+n);
16     printf("%d\n",a[(n+1)/2]);
17     return 0;
18 }
View Code

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: