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 ...
随机推荐
- gerrit-git
解释为什么gerrit中的push是需要用refs/for/master http://stackoverflow.com/questions/10461214/why-is-git-push-ger ...
- 学习Perl6: slice fastq file
需求: 只获取 ath 物种的 hairpin 序列 文件格式如下所示,以>打头的为 header,紧跟的为序列[AUCG]+ (Perl5 regexp 格式) #!/usr/bin/env ...
- oracle 自定义 聚合函数
Oracle自定义聚合函数实现字符串连接的聚合 create or replace type string_sum_obj as object ( --聚合函数的实质就是一个对象 sum ...
- Hibernate,JPA注解@OneToOne_JoinColumn
一对一(One-to-one),外键关联 用例代码如下: 数据库DDL语句 1,CAT表 create table CAT ( id CHAR) not null, create_time ), up ...
- JavaEE基础(二十四)/多线程
1.多线程(多线程的引入) 1.什么是线程 线程是程序执行的一条路径, 一个进程中可以包含多条线程 多线程并发执行可以提高程序的效率, 可以同时完成多项工作 2.多线程的应用场景 红蜘蛛同时共享屏幕给 ...
- C#:隔离点击任务栏上的图标时的“最小化或者恢复”的效果
通常点击任务栏上的图标时,对应窗体实现“最小化或者恢复”的效果.但是在做最小化到托盘时,不希望点击任务栏图标时最小化到托盘,即希望拦截了这些效果(不允许:通过点击任务栏上的图标,实现“最小化或者恢复” ...
- jquery easyui读取json文件乱码
输出的json要求用utf-8,否则因json的编码格式有问题显示不了中文.记事本默认编码是ANSI,若保存的json是由记事本改后的缀名,则json格式有问题,显示中文为乱码. 解决方法:打开.js ...
- [xcode]instruments来检验你的app
原文网址:http://www.cocoachina.com/industry/20140114/7696.html 比较了好多关于instruments 还是发现老外写的比较牛逼.于是果 ...
- JavaScript DOM 编程艺术(第2版)读书笔记(3)
DOM DOM:文档对象模型: 节点 元素节点:DOM的原子是元素节点.<body>.<p>.<ul>之类的元素.元素可以包含其他的元素.没有被包含在其他元素里的唯 ...
- oracle驱动地址
D:\app\LHComputer\product\12.1.0\dbhome_1\ODP.NET\bin\2.x