首页 > 其他 > 详细

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

时间:2017-07-21 15:09:57      阅读:324      评论:0      收藏:0      [点我收藏+]

问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

 

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

原文:http://www.cnblogs.com/Blue233333/p/7217394.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!