http://acm.hdu.edu.cn/showproblem.php?pid=1007

Quoit Design

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 58813    Accepted Submission(s): 15582

Problem Description
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
 
Author
CHEN, Yue
 
Source
  
  给出n个点,找到一个最大半径的圆,满足这个圆每次最多只能覆盖一个点。输出这个最大圆的半径。显然这个最大半径就是最近公共点对的一半,二分找最近距离就好了。、

 #include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define inf 0x3f3f3f3f
struct Point
{
double x,y;
}P[];
inline bool cmpx(Point A,Point B){return A.x<B.x;}
inline bool cmpy(Point A,Point B){return A.y<B.y;}
double dis(Point A,Point B)
{
double dx=(A.x-B.x)*(A.x-B.x);
double dy=(A.y-B.y)*(A.y-B.y);
return sqrt(dx+dy);
}
double solve(int l,int r)
{
if(l==r) return inf;
if(l+==r) return dis(P[l],P[r]);
vector<Point>vp;
int mid=(l+r)>>;
double res=min(solve(l,mid),solve(mid+,r));
for(int i=l;i<=r;++i)
if(P[i].x>=P[mid].x-res&&P[i].x<=P[mid].x+res)
vp.push_back(P[i]);
sort(vp.begin(),vp.end(),cmpy);
for(int i=;i<vp.size();++i){
for(int j=;i+j<vp.size()&&j<;++j){
if(res>dis(vp[i],vp[i+j]))
res=dis(vp[i],vp[i+j]);
}
}
return res;
}
int main()
{
int n;
while(cin>>n&&n){
for(int i=;i<=n;++i)
scanf("%lf%lf",&P[i].x,&P[i].y);
sort(P+,P++n,cmpx);
printf("%.2f\n",solve(,n)/2.0);
}
return ;
}

HDU-1007-最小公共点对的更多相关文章

  1. HDU 1007 Quoit Design(二分+浮点数精度控制)

    Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  2. 【HDU 1007】Quoit Design

    http://acm.hdu.edu.cn/showproblem.php?pid=1007 最近欧式距离模板题. 用分治大法(分治的函数名用cdq纯属个人习惯_(:з」∠)_) 一开始狂M. 后来判 ...

  3. HDU 1533 最小费用最大流(模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1533 这道题直接用了模板 题意:要构建一个二分图,家对应人,连线的权值就是最短距离,求最小费用 要注意void ...

  4. HDU 3374 最小/大表示法+KMP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374 题意:给定一个串s,该串有strlen(s)个循环同构串,要求输出字典序最小的同构串的下标,字典 ...

  5. HDU 2609 最小表示法

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2609 题意:给定n个循环链[串],问有多少个本质不同的链[串](如果一个循环链可以通过找一个起点使得和 ...

  6. HDU 4162 最小表示法

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4162 题意:给定一个只有0-7数字组成的串.现在要由原串构造出一个新串,新串的构造方法:相邻2个位置的数字 ...

  7. HDU 1007 Quoit Design(经典最近点对问题)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1007 Quoit Design Time Limit: 10000/5000 MS (Java/Oth ...

  8. hdu 4289(最小割)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4289 思路:求最小花费,最小割应用,将点权转化为边权,拆点,(i,i+n)之间连边,容量为在城市i的花 ...

  9. HDU 6214 最小割边

    双倍经验题:HDU 6214,3987 求最小割的最小边. 方案一: 首先跑最大流,这个时候割上都满载了,于是将满载的边 cap = 1,其他 inf ,再跑最大流,这个时候限定这个网络的关键边就是那 ...

  10. hdu 1498(最小点覆盖集)

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

随机推荐

  1. Java 常用工具类之 String 类

    String 类的特点: 字符串对象一旦被初始化就不会被改变. //以下代码的区别: String s = "abc"; // 在常量池中创建一个字符串对象, 池中没有就建立, 池 ...

  2. JS-排序详解:冒泡排序、选择排序和快速排序

    JS-排序详解-冒泡排序 说明 时间复杂度指的是一个算法执行所耗费的时间 空间复杂度指运行完一个程序所需内存的大小 稳定指,如果a=b,a在b的前面,排序后a仍然在b的前面 不稳定指,如果a=b,a在 ...

  3. Django页面重定向

    重定向分为永久性重定向和暂时性重定向,在页面上体现的操作就是浏览器会从一个页面自动跳转到另外一个页面.比如用户访问了一个需要权限的页面,但是该用户当前并没有登录,因此我们应该给他重定向到登录页面. 永 ...

  4. C++异常安全、copy and swap

    异常安全的代码是指,满足两个条件 1异常中立性 : 是指当你的代码(包括你调用的代码)引发异常时,这个异常 能保持原样传递到外层调用代码.(异常中立,就是指任何底层的异常都会抛出到上层,也就相当于是异 ...

  5. 在pycharm中导入PyMysql出错,解决方法

    在写Django项目的时候,需要用到数据库中的数据,我们在pycharm中需导入  import PyMySQL; 如果没有该模块会报错,像我这样: 如果你的错误像我这样,那么你按照我的方法应该能搞好 ...

  6. beego——原生SQL查询

    使用Raw SQL查询,无需使用ORM表定义. 多数据库,都可直接使用占位符号?,自动转换. 查询时的参数,支持使用Model Struct和Slice,Array ids := []int{1, 2 ...

  7. 从零到一创建ionic移动app:基础开发环境搭建

    myAPP项目是在Ubuntu14.04下创建   本项目开发node 4.5/cordova 6/ionic 2   第一步 安装nodejs npm install -g n n v4.5.0 使 ...

  8. SqlHelper简单实现(通过Expression和反射)7.MySql数据处理类

    MySql的数据处理类和Sql Server没有太大差别,从思路上来说没有区别,所以此处只是给出代码,不再多加解释了. using System; using System.Configuration ...

  9. 移植MarS Board代码到内核3.0.35

    MarS Board提供的出厂Linux内核是3.0.15的.而Freescale的BSP都早已经更新到3.0.35.为了跟上节奏,我花了点时间把关于marsboard代码从3.0.15移植到了Fre ...

  10. Tomcat 启动内存修改

    内存修改文件 Windows 文件 /bin/catalina.bat Linux 文件 /bin/catalina.sh 方法一 # 设置参数 JAVA_OPTS='-Xms[初始化内存大小] -X ...