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

问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

 

posted @ 2017-07-21 14:14  Blue233333  阅读(132)  评论(0编辑  收藏  举报