博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU1007(最近点对)
阅读量:5236 次
发布时间:2019-06-14

本文共 3181 字,大约阅读时间需要 10 分钟。

Quoit Design

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 54667    Accepted Submission(s): 14401

Problem Description

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
 

 

Author

CHEN, Yue
 

 

Source

 
1 //2017-08-09 2 #include 
3 #include
4 #include
5 #include
6 #include
7 #define mid ((l+r)>>1) 8 9 using namespace std;10 11 const int N = 100010;12 struct Point{13 double x, y;14 }P[N], p1[N], p2[N];15 int n;16 17 bool cmp_x(Point a, Point b){18 return a.x < b.x;19 }20 21 bool cmp_y(Point a, Point b){22 return a.y < b.y;23 }24 25 double distance(Point *a, Point *b){26 return sqrt((a->x - b->x)*(a->x - b->x) + (a->y - b->y)*(a->y - b->y));27 }28 29 //分治,solve(l, r)表示区间[l, r]内的最近点对,solve(l, r) = min(solve(l, mid), solve(mid+1, r), 跨左右子区间的最近点对)30 double solve(int l, int r){31 if(l >= r)return 0;32 if(r - l == 1)return distance(&P[l], &P[r]);33 if(r - l == 2)return min(distance(&P[l], &P[l+1]), distance(&P[l+1], &P[r]));34 double ans = min(solve(l, mid), solve(mid+1, r));35 //暴力x坐标与mid的x坐标相差不超过当前最优解ans的点36 int m = 0;37 for(int i = l; i <= r; i++){38 if(fabs(P[mid].x - P[i].x) <= ans){39 p1[m++] = P[i];40 }41 }42 sort(p1, p1+m, cmp_y);43 for(int i = 0; i < m; i++){44 for(int j = i+1; j < m; j++){45 if(p1[j].y - p1[i].y > ans)break;46 ans = min(ans, distance(&p1[i], &p1[j]));47 }48 }49 return ans;50 }51 52 int main()53 {54 //freopen("dataIn.txt", "r", stdin);55 while(scanf("%d", &n)!=EOF && n){56 for(int i = 0; i < n; i++)57 scanf("%lf%lf", &P[i].x, &P[i].y);58 sort(P, P+n, cmp_x);59 printf("%.2lf\n", solve(0, n-1)/2);60 }61 62 return 0;63 }

 

转载于:https://www.cnblogs.com/Penn000/p/7325701.html

你可能感兴趣的文章
Leetcode 226: Invert Binary Tree
查看>>
http站点转https站点教程
查看>>
解决miner.start() 返回null
查看>>
bzoj 2007: [Noi2010]海拔【最小割+dijskstra】
查看>>
BZOJ 1001--[BeiJing2006]狼抓兔子(最短路&对偶图)
查看>>
C# Dynamic通用反序列化Json类型并遍历属性比较
查看>>
128 Longest Consecutive Sequence 一个无序整数数组中找到最长连续序列
查看>>
定制jackson的自定义序列化(null值的处理)
查看>>
auth模块
查看>>
javascript keycode大全
查看>>
前台freemark获取后台的值
查看>>
log4j.properties的作用
查看>>
游戏偶感
查看>>
Leetcode: Unique Binary Search Trees II
查看>>
C++ FFLIB 之FFDB: 使用 Mysql&Sqlite 实现CRUD
查看>>
Spring-hibernate整合
查看>>
c++ map
查看>>
exit和return的区别
查看>>
discuz 常用脚本格式化数据
查看>>
洛谷P2777
查看>>