【HDU 1007 】Quoit Design 【分治--最近点对问题】
来源:互联网 发布:数据精灵注册机 编辑:程序博客网 时间:2024/05/18 02:43
Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 56279 Accepted Submission(s): 14943
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
ZJCPC2004
题意 : 坐标系中给n个点,求两个点之间最近距离的一半。
分治算法的典型问题
模板
代码
#include<bits/stdc++.h>using namespace std;#define ll long long #define fread() freopen("in.txt","r",stdin)#define fwrite() freopen("out.txt","w",stdout)#define CLOSE() ios_base::sync_with_stdio(false)const int MAXN = 100000 + 10;const int MAXM = 1e6+10;const int mod = 1e9+7;const int inf = 0x3f3f3f3f;struct Note { double x , y ;} Point[MAXN] , Q[MAXN] ;int n ;bool cmpx( Note a , Note b ) { return a.x < b.x || ( a.x == b.x && a.y < b.y ) ; }bool cmpy( Note a , Note b ) { return a.y < b.y ; }double Sqr( double x ) { return x * x ; }double Dis2( Note a , Note b ) { return sqrt(Sqr( a.x - b.x ) + Sqr( a.y - b.y ) ) ; }double DIV( int l , int r ) { double ret = inf*1.0 ; if ( l == r ) return ret ; if ( l + 1 == r ) return Dis2( Point[l] , Point[r] ) ; int mid = (l + r) / 2 ; double d1 = DIV( l , mid ) ; double d2 = DIV( mid + 1 , r ) ; ret = min( d1 , d2 ) ; double d = ret ; int k = 0 ; for (int i = mid ; i >= l ; i -- ) { if ( Point[mid].x - Point[i].x > d ) break ; Q[++k] = Point[i] ; } for (int i = mid + 1 ; i <= r ; i ++ ) { if ( Point[i].x - Point[mid].x > d ) break ; Q[++k] = Point[i] ; } sort( Q + 1 , Q + k + 1 , cmpy ) ; for (int i = 1 ; i < k ; i ++ ) { for (int j = i + 1 ; j <= k && Q[j].y - Q[i].y <= (ll)d ; j ++ ) { ret = min( ret , Dis2( Q[i] , Q[j] ) ) ; } } return ret ;}int main() { while(scanf("%d",&n )&&n){ double x,y; for (int i = 1 ; i <= n ; i ++ ) { scanf( "%lf%lf" , &x,&y) ; Point[i].x = x; Point[i].y = y; } sort( Point + 1 , Point + n + 1 , cmpx ) ; printf( "%.2lf\n" , DIV( 1 , n ) /2 ) ; } return 0 ;}
- HDU 1007 Quoit Design(最近点对问题:分治)
- 【HDU 1007 】Quoit Design 【分治--最近点对问题】
- hdu 1007 Quoit Design (最近点对、分治)
- Hdu 1007 - Quoit Design//分治,最近点对,计算几何
- hdu 1007 Quoit Design(分治法求最近点对)
- hdu 1007 Quoit Design(分治求最近点对)
- hdu 1007 Quoit Design 最近点对(分治)
- HDU 1007 Quoit Design 分治法求最近点对
- HDU 1007 Quoit Design 最近点对 分治法
- hdu 1007 Quoit Design 最近点对(分治)
- 【分治 求最近点对】hdu 1007 Quoit Design
- HDU 1007 Quoit Design(分治法求最近点对问题)
- hdu/hdoj 1007 Quoit Design (最近点对问题)
- HDU 1007 Quoit Design 最近点对问题
- hdu 1007 Quoit Design 最近点对
- hdu 1007 Quoit Design 最近点对
- hdu 1007 Quoit Design (最近点对)
- HDU 1007 Quoit Design 最近点对
- elasticsearch2.4.2使用(一)
- CentOS搭建.NET Core开发环境
- nginx通过CORS实现跨域
- 从iOS 11看怎样设计APP图标
- TabLayout_Viewpage多个界面
- 【HDU 1007 】Quoit Design 【分治--最近点对问题】
- Jenkins 修改启动端口号(Windows)
- Red5流服务器搭建(实现在线直播,流媒体视频播放和在线视频会议)
- Android 文件目录及使用
- Eclipse安装goclipse插件方法
- 日期计算器
- 序列化的几种方式
- 归并排序
- k短路-【SDOI-2010-魔法猪学院】