*HDU 1007 计算几何
Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 48729 Accepted Submission(s): 12823
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 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.
each test case, print in one line the radius of the ring required by
the Cyberground manager, accurate up to 2 decimal places.
1 1
1 1
0 0
0 1.5
0
//分治法求最近点对模板。详解《算法导论》610页。//至于将y坐标只预排序一次怎么写呢。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
int a[];
struct nod
{
double x,y;
}p[];
bool cmpx(nod p1,nod p2)
{
return p1.x<p2.x;
}
bool cmpy(int a1,int a2)
{
return p[a1].y<p[a2].y;
}
double dis(int s,int e)
{
return sqrt((p[s].x-p[e].x)*(p[s].x-p[e].x)+(p[s].y-p[e].y)*(p[s].y-p[e].y));
}
double Min(double a1,double a2,double a3)
{
return a1<a2?(a1<a3?a1:a3):(a2<a3?a2:a3);
}
double fenzhi(int s,int e)
{
if(s+==e)
return dis(s,e);
if(s+==e)
return Min(dis(s,s+),dis(s,e),dis(s+,e));
int mid=(s+e)>>;
double ans=min(fenzhi(s,mid),fenzhi(mid+,e));
int k=;
for(int i=s;i<=e;i++)
{
if(fabs(p[i].x-p[mid].x)<ans)
a[k++]=i;
}
sort(a,a+k,cmpy);
for(int i=;i<k;i++)
for(int j=i+;j<=i+&&j<k;j++)
{
if(p[a[j]].y-p[a[i]].y>=ans) break;
else ans=min(ans,dis(a[i],a[j]));
}
return ans;
}
int main()
{
while(scanf("%d",&n)&&n)
{
for(int i=;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
sort(p,p+n,cmpx);
double ans=fenzhi(,n-);
printf("%.2lf\n",ans/);
}
return ;
}
*HDU 1007 计算几何的更多相关文章
- 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(计算几何の最近点对)
Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings ...
- HDU 1007 Quoit Design【计算几何/分治/最近点对】
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 【HDU 1007】Quoit Design
http://acm.hdu.edu.cn/showproblem.php?pid=1007 最近欧式距离模板题. 用分治大法(分治的函数名用cdq纯属个人习惯_(:з」∠)_) 一开始狂M. 后来判 ...
- hdu 2108:Shape of HDU(计算几何,判断多边形是否是凸多边形,水题)
Shape of HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- 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 [算法] 答案为平面最近点对距离除以2 [代码] #include <algorith ...
- 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个点,问最近的两个点之间的距离的一半是多少. 思路:用分治做.把整体分为左右两个部分,那么 ...
随机推荐
- Swift 定义函数 参数 返回值
定义多参数函数 - 用func声明函数 func name(parameters) -> return type { function body } func halfOpenRangeLen ...
- js学习进阶-元素获取及样式设置
var imgs = document.querySelectorAll("article img"); 获得article元素的直接或间接子孙的所有img元素, <arti ...
- VC++6.0 Win32 C2065:SM_XVIRTUALSCREEN
百度了了一大堆,都说让重装vc++6.0,然而并没有什么卵用. 解决办法:找到你的vc6.0安装路径下的WINDOWS.H,将0x0400改为0x0500 Window各个版本对应的宏值WINVER:
- LeetCode之263. Ugly Number
------------------------------------------------------------- 如果一个数的质因子只包括2,3,5,那么这个数n可以表示为:n=2x+3y+ ...
- 手把手教你玩转nginx负载均衡(五)----配置后端服务器组
引言 在前面几篇中,我们成功的搭建起了一台nginx服务器,所以我们要重复前面的步骤,把服务器的数量增加到3台以上,我这里已经建好了另外两台,分别是centos7-22,centos7-23,对应的i ...
- C# oracle odp.net 32位/64位版本的问题
问题如下: 系统是win7 64位,技术 asp.net mvc 4, 数据库 oracle 11g. 由于某些原因只能使用 32的 ODP.NET ( Oracle Data Provider ), ...
- 使用Nito.AsyncEx实现异步锁(转)
转载地址:http://www.cnblogs.com/1zhk/p/5269279.html Lock是常用的同步锁,但是我们无法在Lock的内部实现异步调用,比如我们无法使用await. 以下面的 ...
- 使用Lucene索引和检索POI数据
1.简介 关于空间数据搜索,以前写过<使用Solr进行空间搜索>这篇文章,是基于Solr的GIS数据的索引和检索. Solr和ElasticSearch这两者都是基于Lucene实现的,两 ...
- 【学习篇:他山之石,把玉攻】JavaScript Date() 对象 及 格式化
Date 对象用于处理日期和时间. 创建 Date 对象的语法: var myDate=new Date() Date 对象会自动把当前日期和时间保存为其初始值. 参数形式有以下5种: new ...
- 在Asp.Net MVC 中配置 Serilog
Serilog 是一种非常简便记录log 的处理方式,使用Serilog可以生成本地的text文件, 也可以通过 Seq 来在Web界面中查看具体的log内容. 接下来就简单的介绍一下在Asp.Net ...