hdu1007 Quoit Design 分治
来源:互联网 发布:地震科普知识网络竞赛 编辑:程序博客网 时间:2024/05/21 18:38
Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 53708 Accepted Submission(s): 14156
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
题目大意是,给定n个点,求解n个点中距离最近的两个点的距离的一半,采用分治思想
#include<iostream> #include<cmath> #include<algorithm> using namespace std; int n; struct node { double x; double y; }p[100005]; int a[100005]; double cmpx(node a,node b) { return a.x<b.x; } double cmpy(int a,int b) { return p[a].y<p[b].y; } double dis(node a,node b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } double find(int l,int r){ if(r==l+1) //如果只有一个或者两个点直接求最短长度 return dis(p[l],p[r]); if(l+2==r) return min(dis(p[l],p[r]),min(dis(p[l],p[l+1]),dis(p[l+1],p[r]))); //递归求解 int mid=(l+r)>>1; //从中间分开,进行分治 double ans=min(find(l,mid),find(mid+1,r)); //寻找左右两边最小值 int i,j,cnt=0; for(i=l;i<=r;i++){ //统计距离中点距离小于ans的点 if(p[i].x>=p[mid].x-ans&&p[i].x<=p[mid].x+ans) a[cnt++]=i; } sort(a,a+cnt,cmpy); //对y轴进行排序 for(i=0;i<cnt;i++){ //查找是否存在最小的点 for(j=i+1;j<cnt;j++){ if(p[a[j]].y-p[a[i]].y>=ans) break; ans=min(ans,dis(p[a[i]],p[a[j]])); } } return ans; } int main(){ int i; while(scanf("%d",&n)!=EOF){ if(!n) break; for(i=0;i<n;i++) scanf("%lf %lf",&p[i].x,&p[i].y); sort(p,p+n,cmpx); printf("%.2lf%\n",find(0,n-1)/2); } return 0; }
阅读全文
0 0
- HDU1007 Quoit Design 【分治】
- HDU1007 Quoit Design 分治
- hdu1007 Quoit Design 分治
- HDU1007:Quoit Design(分治)
- HDU1007 Quoit Design(分治法)
- hdu1007 Quoit Design 【计算几何+分治】
- hdu1007 Quoit Design 平面最近点对(分治)
- hdu1007 Quoit Design (分治+鸽舍原理)
- hdu1007 Quoit Design【平面最近点对+分治】
- HDU1007 Quoit Design
- hdu1007-Quoit Design
- HDU1007 Quoit Design
- hdu1007 Quoit Design
- HDU1007 Quoit Design
- hdu1007——Quoit Design
- ZOJ2107——Quoit Design&&HDU1007——Quoit Design
- hdu1007 Quoit Design(最近点对)
- hdu1007 Quoit Design (最近点对)
- 设计模式讲解与代码实践(七)——适配器(基于对象)
- laravel中,提交表单后给出提示例如添加成功,添加失败等等
- UNICODE与ASCII的区别
- Sumsets
- 使用UE4尝试复刻一个游戏
- hdu1007 Quoit Design 分治
- 二分图最大匹配
- Java中的Filter过滤器
- Android Material Design中的BottomNavigationView实现底部导航栏
- 加密时java.security.InvalidKeyException: Illegal key size or default parameters解决办法
- 手机连接电脑后弹出窗口名字修改(MTK)
- 模拟实现strcat函数
- Spring启动过程
- 字符设备驱动--中断方式下的按键驱动