杭电ACM1173

http://acm.hdu.edu.cn/showproblem.php?pid=1173

求出x,y的中位数,即为答案,代码中运用快排

View Code
 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 double x[1000000],y[1000000];
 4 int cmp(const void*a,const void*b)
 5 {
 6  return *(double *)a>*(double *)b?1:-1;
 7 }//快排
 8 int main()
 9 {
10  int n,i;
11  while(scanf("%d",&n)&&n)
12     {
13      for(i=0;i<n;i++)
14         scanf("%lf%lf",&x[i],&y[i]);
15      qsort(x,n,sizeof(x[0]),cmp);
16      qsort(y,n,sizeof(y[0]),cmp);
17      printf("%0.2lf %0.2lf\n",x[(n-1)/2],y[(n-1)/2]);//求出中位数
18     }
19  return 0;
20 }

 

posted @ 2013-03-19 19:50  执着追求的IT小小鸟  阅读(138)  评论(0编辑  收藏  举报