HDU 1007 Quoit Design
2015-06-19 13:41
453 查看
Quoit Design
Time Limit: 5000msMemory 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
ZJCPC2004解题:最近点对问题,利用分治。
其实就是归并排序,先按y排序,然后把按y排序的数组在递归的过程中按x排序,最后又恢复成按y排序。是不是有点像划分树。。。
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; const int INF = 0x3f3f3f3f; struct Point{ double x,y; int index; Point(double tx = 0,double ty = 0,int z = 0){ x = tx; y = ty; index = z; } }Bx[maxn],By[maxn],Bz[maxn],tmp[maxn]; bool cmpx(const Point &a,const Point &b){ return a.x < b.x; } bool cmpy(const Point &a,const Point &b){ return a.y < b.y; } double calc(const Point &a,const Point &b){ return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y)); } double closet(int low,int high){ double ret = INF; if(low + 2 >= high){ for(int i = low; i <= high; ++i) for(int j = i + 1; j <= high; ++j) ret = min(ret,calc(Bx[i],Bx[j])); return ret; } int mid = (low + high)>>1,l = low,r = mid+1,s = low,cnt = low; for(int i = low; i <= high; ++i) if(By[i].index <= mid) Bz[l++] = By[i]; else Bz[r++] = By[i]; for(int i = low; i <= high; ++i) By[i] = Bz[i]; ret = min(closet(low,mid),closet(mid+1,high)); for(l = low,r = mid+1; l <= mid && r <= high;) if(Bz[l].y < Bz[r].y) tmp[s++] = Bz[l++]; else tmp[s++] = Bz[r++]; while(l <= mid) tmp[s++] = Bz[l++]; while(r <= high) tmp[s++] = Bz[r++]; for(int i = low; i <= high; ++i) By[i] = Bz[i] = tmp[i]; for(int i = low; i <= high; ++i) if(fabs(Bz[i].x - Bz[mid].x) < ret) tmp[cnt++] = Bz[i]; for(int i = low; i < cnt; ++i) for(int j = i + 1; j < cnt && Bz[j].y - Bz[i].y < ret; ++j) ret = min(ret,calc(Bz[i],Bz[j])); return ret; } int main(){ int n; while(scanf("%d",&n),n){ for(int i = 0; i < n; ++i) scanf("%lf %lf",&Bx[i].x,&Bx[i].y); sort(Bx,Bx+n,cmpx); for(int i = 0; i < n; ++i) By[i] = Point(Bx[i].x,Bx[i].y,i); sort(By,By+n,cmpy); printf("%.2f\n",closet(0,n-1)/2); } return 0; }
View Code
相关文章推荐
- 两数之和
- openlayers Uncaught TypeError: Cannot read property 'wrapDateLine' of null
- sqlite python脚本
- iOS使用脚本批量打渠道包
- 用户调查报告
- [IOS]从相册获取图片和视频进行上传
- C# unicode编码 中文显示
- a href=#与 a href=javascript:void(0) 的区别
- jquery 同步和异步请求
- centos redis自启动相关
- mysql grant
- 抢答器设计
- 手机安全卫士02
- aptitude与apt-get常用选项
- Storm WordCount Topology学习
- Unable to open connection to supplicant on "/data/misc/wifi/sockets/wlan0"
- jvm之xms、xmx等参数分析
- 【性能诊断】七、并发场景的性能分析(windbg案例,线程阻塞)
- 技术演绎之 [ hadoop] 内部介绍
- 第16周-异常处理和命名空间-项目2-有些数的阶乘不算了