Quoit Design - HDU 1007 分治
来源:互联网 发布:1080ti 知乎 编辑:程序博客网 时间:2024/06/05 22:50
Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 30473 Accepted Submission(s): 8008
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.
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
20 01 121 11 13-1.5 00 00 1.50
Sample Output
0.710.000.75
AC代码如下:
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;struct node{ double x,y;}dian[100010];int a[100010];bool cmpx(node a,node b){ return a.x<b.x;}bool cmpy(int a,int b){ return dian[a].y<dian[b].y;}double dis(int i,int j){ return sqrt((dian[i].x-dian[j].x)*(dian[i].x-dian[j].x)+(dian[i].y-dian[j].y)*(dian[i].y-dian[j].y));}double fen(int l,int r){ int i,j,num=0; if(l+1==r) return dis(l,r); if(l+2==r) return min(dis(l,r),min(dis(l,l+1),dis(l+1,r))); int mi=(l+r)/2; double ans=min(fen(l,mi),fen(mi+1,r)); for(i=l;i<=r;i++) if(fabs(dian[i].x-dian[mi].x)<=ans) a[++num]=i; sort(a+1,a+1+num,cmpy); for(i=1;i<=num;i++) for(j=i+1;j<=num;j++) { if(dian[a[j]].y-dian[a[i]].y>=ans) break; ans=min(ans,dis(a[i],a[j])); } return ans;}int main(){ int n,i,j,k; while(~scanf("%d",&n) && n) { for(i=1;i<=n;i++) scanf("%lf%lf",&dian[i].x,&dian[i].y); sort(dian+1,dian+1+n,cmpx); printf("%.2f\n",fen(1,n)/2); }}
0 0
- Quoit Design - HDU 1007 分治
- 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 1007 Quoit Design (最近点对、分治)
- Hdu 1007 - Quoit Design//分治,最近点对,计算几何
- hdu 1007 Quoit Design(分治法求最近点对)
- hdu 1007 Quoit Design(分治求最近点对)
- hdu 1007 Quoit Design 最近点对(分治)
- Java抽象类与接口的区别
- cocos2d-x 2.2.2版本实现卡牌翻牌动作
- 优先队列
- UVA532
- HDU 2074 叠筐
- Quoit Design - HDU 1007 分治
- HDU 2075 A|B?
- js的Prototype属性 解释及常用方法
- C++windows内核编程笔记day06 代码创建菜单
- 端口号的理解
- HDU 2076 夹角有多大(题目已修改,注意读题)
- 找工作笔试面试那些事儿(16)---linux相关知识点(1)
- Hibernate调试——定位查询源头
- 0cfnQUEyqHS