*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个点,问最近的两个点之间的距离的一半是多少. 思路:用分治做.把整体分为左右两个部分,那么 ...
随机推荐
- 【python】with的实现方法
来源:http://www.ibm.com/developerworks/cn/opensource/os-cn-pythonwith/#icomments 重点: with方法适用于需要分配和清理资 ...
- Ionic 常用插件
ionic扩展插件 1.ionic-timepicker 时间选择 https://github.com/rajeshwarpatlolla/ionic-timepicker 2.ionic-da ...
- iOS 对象和json互相转换
// 将字典或者数组转化为JSON串 - (NSData *)toJSONData:(id)theData { NSError *error = nil; NSData *jsonData = [NS ...
- 总结移动安全的测试点及详解allowbackup漏洞
一.移动应用APP可能面临以下威胁: 木马--二次打包, 病毒--账号窃取, 篡改--资源篡改, 破解--广告植入, 钓鱼--信息劫持 二.移动终端APP安全评估的7个方向: 通信安全,敏感信息安全 ...
- JS中的if和else的用法以及基础语法
正常里的变量方式.var a = 10; 针对整数.var b = 3.14; 针对的小数点.var c = "你好":双引号或者单引号引起来的是定义字符串. 一.类型转换(强制转 ...
- 实现滑动可固定header以及页面刷新
用到的布局:SwiperRefreshLayout,AppBarLayout,ToolBar,CollapsingToolbarLayout,CoordinatorLayout 布局 <?xml ...
- C#winForm调用WebService的远程接口
Web Service 的创建简单编码.发布和部署 上一篇详细概述了WebService的创建,编码,发布和部署,那么作为客户端的程序如何访问远程端的WebService 接下来看一下具体步骤: ...
- ubuntu14.04下配置Java环境以及安装最新版本的eclipse
首先是配置JDK 步骤一:下载最新版本的JDK,链接:http://www.oracle.com/technetwork/java/javase/downloads/index.html 步骤二:首先 ...
- Spring MVC类型转换
类型转换器引入 为什么页面上输入"12",可以赋值给Handler方法对应的参数?这是因为框架内部帮我们做了类型转换的工作.将String转换成int 但默认类型转换器并不是可以将 ...
- Good Bye 2016
A - New Year and Hurry (water) #include <bits/stdc++.h> using namespace std; int main() { ]; ; ...