*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个点,问最近的两个点之间的距离的一半是多少. 思路:用分治做.把整体分为左右两个部分,那么 ...
随机推荐
- 考前预习(Ubuntu配备)
这几天考前预习,趁现在不想预习,写点之前就想写的东西吧. 贴一下个人认为有用的,在Ubuntu装机后的一些小事.不过挺杂的,主要是拿来给以后的自己看,以及让现在无聊的我有点事做. 首先,Ubuntu官 ...
- C# Interface的使用方法探讨
接口是把公共实例(非静态)的方法和属性结合起来,以封装特定功能的一个集合,一旦定义了接口,就可以在类中使用实现接口中的所有成员,接口可以看作创建者和使用者之间的契约,一旦实现了接口,就不要轻易变动(如 ...
- SQL批量增加修改数据
insert into A表(字段1,字段2) select 字段1,字段2 From B表 [注:字段类型.字段数应相同] --批量进行修改ID值 declare @i int begin )) F ...
- git 删除分支
1,删除本地分支 git branch -D 本地分支名 2,删除远程分支 git push origin --delete 远程分支名 注意:如果只删除了本地分支而没有删除远程分支,再新建一个相同名 ...
- "传成老树白茶"献礼母亲节 邀市民品茗感受茶文化
5月8日下午,传成老树白茶巡回中国公益品鉴会第七十站,走进福州马尾区东方名城传成老树白茶文化馆. 本次品鉴会活动以“感恩母亲节”为主题,以马尾船政文化为背景,邀福州市民一起品鉴白茶,感受中国茶文化. ...
- cron(CronTrigger)表达式用法
CronTrigger CronTriggers往往比SimpleTrigger更有用,如果您需要基于日历的概念,而非SimpleTrigger完全指定的时间间隔,复发的发射工作的时间表.CronTr ...
- Redsi和Memcached区别总结
首先谈谈Redis和Memcached它们都是缓存在内存中的,唯一的区别就是Redis它本身会周期性的把 更新的一些数据写入到磁盘或者修改操作写入追加的记录文件中,并且在此基础上实现master-sl ...
- C# 取整函数
向上取整math.ceiling(1) = 1math.ceiling(1.1) = 2math.ceiling(1.5) = 2向下取整math.float(1) = 1math.float(1.1 ...
- F#之旅1 - Why use F#?为什么要用F#?
原文地址:http://fsharpforfunandprofit.com/why-use-fsharp/ Why use F#?Why you should consider using F# fo ...
- 被Unity5坑惨了
各种不明所以的crash,导致crash率从0.5%瞬间暴涨到10%. Unity5还是非常不稳定,慎入慎入...