暂鸽

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define N 100010
using namespace std;
void chkmin(double x,double y) {if (x>y) x=y;}
int n;
struct point
{
double x,y;
point(){};
point(double _x,double _y)
{
x=_x,y=_y;
}
point operator - (const point &b) const
{
return point(x-b.x,y-b.y);
}
double norm()const
{
return sqrt(x*x+y*y);
}
bool operator < (const point &a) const
{
return x<a.x;
}
}p[N];
double solve(int l,int r)
{
if (l+1==r) return 1e20;
int mid=l+r>>1;
double x0=(p[mid-1].x+p[mid].x)/2.0;
double d=min(solve(l,mid),solve(mid,r));
static point a[N],b[N],c[N];
int b_n=0,c_n=0;
int L=l,R=mid;
for (int i=l;i<r;i++)
{
if (L<mid && (R==r || p[L].y<p[R].y))
{
a[i]=p[L++];
if (x0-d<a[i].x) b[b_n++]=a[i];
}
else
{
a[i]=p[R++];
if (a[i].x<x0+d) c[c_n++]=a[i];
}
}
for (int i=l;i<r;i++) p[i]=a[i];
for (int i=0,j=0;i<b_n || j<c_n;)
{
if (i<b_n && (j==c_n || b[i].y<c[j].y))
{
for (int k=j-1;k>=0;k--)
{
if (b[i].y-d>=c[k].y) break;
d=min(d,(c[k]-b[i]).norm());
}
i++;
}
else
{
for (int k=i-1;k>=0;k--)
{
if (c[j].y-d>=b[k].y) break;
d=min(d,(b[k]-c[j]).norm());
}
j++;
}
}
return d;
}
int main()
{
while (scanf("%d",&n),n)
{
for (int i=0;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
sort(p,p+n);
printf("%.2f\n",solve(0,n)/2.0);
}
return 0;
}

HDU 1007 Quoit Design | 平面分治的更多相关文章

  1. HDU 1007 Quoit Design 平面内最近点对

    http://acm.hdu.edu.cn/showproblem.php?pid=1007 上半年在人人上看到过这个题,当时就知道用分治但是没有仔细想... 今年多校又出了这个...于是学习了一下平 ...

  2. hdu 1007 Quoit Design(分治)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007 题意:给出n个点求最短的两点间距离除以2. 题解:简单的分治. 其实分治就和二分很像二分的写df ...

  3. hdu 1007 Quoit Design (经典分治 求最近点对)

    Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings ...

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

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

  5. HDU 1007 Quoit Design【计算几何/分治/最近点对】

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

  6. hdu 1007 Quoit Design 分治求最近点对

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

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

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

  8. hdu 1007 Quoit Design (最近点对问题)

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

  9. poj 1007 Quoit Design(分治)

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

随机推荐

  1. ReplaceChar

    好吧,给个char的,替换单个字符.这样会快一些吧,这个是置换,连长度都不用了 bool ReplaceChar(char *str,const char src, const char dst){ ...

  2. [vijos p1028] 魔族密码

    描述 风之子刚走进他的考场,就……花花:当当当当~~偶是魅力女皇——花花!!^^(华丽出场,礼炮,鲜花)风之子:我呕……(杀死人的眼神)快说题目!否则……-_-###花花:……咦~~好冷~~我们现在要 ...

  3. struts2之输入验证

    输入校验主要分为两种: 基于客户端的校验: 客户端校验主要作用是防止正常浏览者的误输入,仅能对输入进行初步过滤:对于一些用户恶意行为,客户端校验则无能为力. 基于服务端的校验: 服务器接收客户端提交的 ...

  4. macOs 使用Homebrew升级到MySQL 8系列之后,php无法连接解决方法

    当前时间2018-9-28 在使用brew install mysql 默认安装为 MySQL 8,但是使用php连接到数据库之后,出现了这种错误 (Unexpected server respose ...

  5. 微信网页授权access_token与基础支持的access_token

    问题1:网页授权access_token与分享的jssdk中的access_token一样吗? 答:不一样.网页授权access_token 是一次性的,而基础支持的access_token的是有时间 ...

  6. [CodeChef]RIN(最小割)

    Description  有m门课可以在n个学期内学习,第i门课在第j个学期的收益是\(X_{i,j}\),一个学期可以学多门课,有的课之间有依赖关系,即必须先学a再学b,求最大收益.n,m<= ...

  7. 总结 Date 2017.09.23

    总结 Date 2017.09.23 <1>统计数字 某次科研调查时得到了n个自然数,每个数均不超过1500000000(1.5*10^9).已知不相同的数不超过10000个,现在需要统计 ...

  8. poj 1759 二分搜索

    题意:N个等差数列,初项X_i,末项Y_i,公差Z_i,求出现奇数次的数? 思路: 因为只有一个数出现的次数为奇数个 假设 第二个数字的个数为 奇数个,其余全部都是偶数个 ,累计出现的次数 a1偶数 ...

  9. 通过aop添加日志管理

    1.使用spring 的 aop 技术切到自定义注解上,所以先创建一个自定义注解类 import java.lang.annotation.*; @Target(ElementType.METHOD) ...

  10. SpringMVC---简单登录例子

    所需jar包aopalliance-1.0.jar.commons-logging-1.2.jar.spring-aop-5.0.0.RELEASE.jar.spring-beans-5.0.0.RE ...