HDU 1007 Quoit Design

Quoit Design

Time Limit: 5000ms
Memory Limit: 32768KB
This problem will be judged on  HDU. Original ID: 1007
64-bit integer IO format: %I64d      Java class name: Maina
Have you ever played quoit in a playground? Quoit is a game in which flat rings are pitched at some toys, with all the toys encircled awarded.
In the field of Cyberground, the position of each toy is fixed, and the ring is carefully designed so it can only encircle one toy at a time. On the other hand, to make the game look more attractive, the ring is designed to have the largest radius. Given a configuration of the field, you are supposed to find the radius of such a ring.

Assume that all the toys are points on a plane. A point is encircled by the ring if the distance between the point and the center of the ring is strictly less than the radius of the ring. If two toys are placed at the same point, the radius of the ring is considered to be 0.
 

Input

The input consists of several test cases. For each case, the first line contains an integer N (2 <= N <= 100,000), the total number of toys in the field. Then N lines follow, each contains a pair of (x, y) which are the coordinates of a toy. The input is terminated by N = 0.
 

Output

For each test case, print in one line the radius of the ring required by the Cyberground manager, accurate up to 2 decimal places. 
 

Sample Input

2
0 0
1 1
2
1 1
1 1
3
-1.5 0
0 0
0 1.5
0

Sample Output

0.71
0.00
0.75

Source

 
解题:最近点对问题,利用分治。
 
其实就是归并排序,先按y排序,然后把按y排序的数组在递归的过程中按x排序,最后又恢复成按y排序。是不是有点像划分树。。。
 
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 100005;
 4 const int INF = 0x3f3f3f3f;
 5 struct Point{
 6     double x,y;
 7     int index;
 8     Point(double tx = 0,double ty = 0,int z = 0){
 9         x = tx;
10         y = ty;
11         index = z;
12     }
13 }Bx[maxn],By[maxn],Bz[maxn],tmp[maxn];
14 bool cmpx(const Point &a,const Point &b){
15     return a.x < b.x;
16 }
17 bool cmpy(const Point &a,const Point &b){
18     return a.y < b.y;
19 }
20 double calc(const Point &a,const Point &b){
21     return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
22 }
23 double closet(int low,int high){
24     double ret = INF;
25     if(low + 2 >= high){
26         for(int i = low; i <= high; ++i)
27             for(int j = i + 1; j <= high; ++j)
28                 ret = min(ret,calc(Bx[i],Bx[j]));
29         return ret;
30     }
31     int mid = (low + high)>>1,l = low,r = mid+1,s = low,cnt = low;
32     for(int i = low; i <= high; ++i)
33         if(By[i].index <= mid) Bz[l++] = By[i];
34         else Bz[r++] = By[i];
35     for(int i = low; i <= high; ++i) By[i] = Bz[i];
36     ret = min(closet(low,mid),closet(mid+1,high));
37     for(l = low,r = mid+1; l <= mid && r <= high;)
38         if(Bz[l].y < Bz[r].y) tmp[s++] = Bz[l++];
39         else tmp[s++] = Bz[r++];
40     while(l <= mid) tmp[s++] = Bz[l++];
41     while(r <= high) tmp[s++] = Bz[r++];
42     for(int i = low; i <= high; ++i) By[i] = Bz[i] = tmp[i];
43     for(int i = low; i <= high; ++i)
44         if(fabs(Bz[i].x - Bz[mid].x) < ret) tmp[cnt++] = Bz[i];
45     for(int i = low; i < cnt; ++i)
46         for(int j = i + 1; j < cnt && Bz[j].y - Bz[i].y < ret; ++j)
47             ret = min(ret,calc(Bz[i],Bz[j]));
48     return ret;
49 }
50 int main(){
51     int n;
52     while(scanf("%d",&n),n){
53         for(int i = 0; i < n; ++i)
54             scanf("%lf %lf",&Bx[i].x,&Bx[i].y);
55         sort(Bx,Bx+n,cmpx);
56         for(int i = 0; i < n; ++i)
57             By[i] = Point(Bx[i].x,Bx[i].y,i);
58         sort(By,By+n,cmpy);
59         printf("%.2f\n",closet(0,n-1)/2);
60     }
61     return 0;
62 }
View Code

 

转载于:https://www.cnblogs.com/crackpotisback/p/4588421.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值