zoj 2107&&hdu 1007最近点对问题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1107
Quoit Design
Time Limit: 5 Seconds Memory Limit: 32768 KB
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
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
参考了模板写的,确实不是很懂
来源:http://blog.csdn.net/cxiaokai/article/details/6661005
参考资料:http://blog.csdn.net/lishuhuakai/article/details/9133961
http://blog.csdn.net/hackbuteer1/article/details/7482232
尚待理解
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#define MAXX 100005
using namespace std; struct point
{
double x;
double y;
}p[MAXX],p1[MAXX],p2[MAXX]; bool cmpx(point a,point b)
{
return a.x < b.x;
}
bool cmpy(point a,point b)
{
return a.y < b.y;
}
double dis(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double minn(double a,double b)
{
return a > b ? b : a;
}
double closest(int l,int r)
{
if(l+ == r)return dis(p1[l],p1[r]);
if(l+ == r)
return minn(dis(p1[l],p1[l+]),minn(dis(p1[l],p1[r]),dis(p1[l+],p1[r])));
int mid=(l+r)>>;
double ans=minn(closest(l,mid),closest(mid+,r));
int cn=;
for(int i=l; i<=r; i++)
{
if(p1[i].x>=p1[mid].x-ans&&p1[i].x<=p1[mid].x+ans)
{
p2[cn++]=p1[i];
}
}
sort(p2,p2+cn,cmpy);
for(int i=; i<cn; i++)
{
for(int j=i+; j<cn; j++)
{
if(p2[j].y-p2[i].y>=ans)
break;
ans=minn(ans,dis(p2[i],p2[j]));
}
}
return ans;
} int main()
{ int n;
while(scanf("%d",&n)!=EOF&&n)
{
for(int i=; i<n; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
p1[i]=p[i];
}
sort(p1,p1+n,cmpx);
double dist=closest(,n-);
printf("%.2lf\n",dist/);
}
return ;
}
zoj 2107&&hdu 1007最近点对问题的更多相关文章
- hdu 1007最近点对问题
先说下题意,很简单,给n个点的坐标,求距离最近的一对点之间距离的一半.第一行是一个数n表示有n个点,接下来n行是n个点的x坐标和y坐标,实数. 这个题目其实就是求最近点对的距离.主要思想就是分治.先把 ...
- hdu 1007 最近点对问题(Splay解法)
为什么要写这个题..经典啊,当然,别以为我用分治做的,不过主要思想还是那神奇的六个点共存(一个h*2h的矩形中最多能放下多少个点使得两两距离不超过h) 其实我是在这里看到的 http://commun ...
- HDU 1007 Quoit Design(二分+浮点数精度控制)
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU 1007 Quoit Design(经典最近点对问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1007 Quoit Design Time Limit: 10000/5000 MS (Java/Oth ...
- HDU 1007 Quoit Design 平面内最近点对
http://acm.hdu.edu.cn/showproblem.php?pid=1007 上半年在人人上看到过这个题,当时就知道用分治但是没有仔细想... 今年多校又出了这个...于是学习了一下平 ...
- HDU 1007:Quoit Design(分治求最近点对)
http://acm.hdu.edu.cn/showproblem.php?pid=1007 题意:平面上有n个点,问最近的两个点之间的距离的一半是多少. 思路:用分治做.把整体分为左右两个部分,那么 ...
- HDU 1007(套圈 最近点对距离)
题意是求出所给各点中最近点对的距离的一半(背景忽略). 用分治的思想,先根据各点的横坐标进行排序,以中间的点为界,分别求出左边点集的最小距离和右边点集的最小距离,然后开始合并,分别求左右点集中各点与中 ...
- hdu 1007 Quoit Design(分治法求最近点对)
大致题意:给N个点,求最近点对的距离 d :输出:r = d/2. // Time 2093 ms; Memory 1812 K #include<iostream> #include&l ...
- HDU 1007 Quoit Design(计算几何の最近点对)
Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings ...
随机推荐
- HorizontalScrollView水平滑动
xml布局 <HorizontalScrollView android:id="@+id/hsv" android:layout_ ...
- 【MFC三天一个游戏】之 局域网黑白棋
欢迎加入我们的QQ群,无论你是否工作,学生,只要有c / vc / c++ 编程经验,就来吧!158427611 花了三天上班时间,妈的上班写就是不能静下心来,擦,要防BOSS巡山.... 以前也写过 ...
- Servlet乱码
request.setCharacterEncoding():是设置从request中取得的值或从数据库中取出的值 (只管post方式提交的问题///get需在server.xml中的: < ...
- Java简单数据类型转换
1. Integer<---String (1) Integer x = new Integer(Integer.parseInt(String)); 2. Integer<--- ...
- top.location.href和localtion.href有什么不同
top.location.href=”url” 在顶层页面打开url(跳出框架) self.location.href=”url” 仅在本页面打开url地址 pare ...
- jdk8飞行记录器配置
jdk8提供了jmc工具,应该比visualvm厉害吧 下面贴一份tomcat的配置,自己留个备份,把下面的内容粘贴到tomcat setenv.sh就可以了 nowday=`date +%Y%m%d ...
- arduino 蓝牙控制RGB LED灯
/* 日期:2016.9.2 功能:arduino 蓝牙控制RGB LED灯 元件: 跳线公公头 * 8 rgbled, 220欧电阻 蓝牙模块 接线: 蓝牙模块VCC,GND分别接5V,GND;TX ...
- 这个Glance的界面该怎么看出问题,为什么状态是SOCKT?
这个glance的状态图有问题吗?
- 快速稳定的维护PHP
Just to recap, previously we'd have this sort of thing: namespace me\adamcameron\testApp; use Guzzle ...
- android bluetooth蓝牙移植
http://blog.csdn.net/zhengmeifu/article/details/7705172 前段时间移植神念系统需要使用到bluetooth功能,现将移植过程中碰到的问题简要列一下 ...