暂鸽

#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. maven 使用错误

    使用mvn test mvn test -Dtest=测试包名.测试类名时 [ERROR] Failed to execute goal org.apache.maven.plugins:maven- ...

  2. PHP成随机字符串

    生成随机字符串 /** * 随机字符串 * @param int $len * @return string */ function randomStr($len = 32) { $chars = & ...

  3. HAN模型理解1

    HAN 模型 最开始看这个模型是看的这个解释: RNN+Attention(HAN) 文本分类 阅读笔记 - 今天做作业没的文章 - 知乎 https://zhuanlan.zhihu.com/p/4 ...

  4. dubbo的rpc异常

    Exception in thread "main" com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method ...

  5. Android面试收集录17 Android进程优先级

    在安卓系统中:当系统内存不足时,Android系统将根据进程的优先级选择杀死一些不太重要的进程,优先级低的先杀死.进程优先级从高到低如下. 前台进程 处于正在与用户交互的activity 与前台act ...

  6. 4-linux基本命令

    1. cd命令 cd 回当前用户 家目录   cd /home  进入home目录 (绝对路径)   (相对路径)   cd –  上一目录和当前目录来回切换(主要用于返回上一目录)   cd .   ...

  7. 您的手机上未安装应用程序 android 点击快捷方式提示未安装程序的解决

    最近APP出现一个很奇怪的问题,在Android 4.4.2和android 4.4.3系统上点击应用的快捷方式,打不开应用,而且会提示未安装程序. 确认了应用的MainActivity中设置了and ...

  8. 怎么将oracle的sql文件转换成mysql的sql文件-- 费元星

    http://jingyan.baidu.com/article/ca41422fe01f251eaf99ed6e.html

  9. Eclipse 工作空间(Workspace)---Eclipse教程第07课

    Eclipse 工作空间(Workspace) eclipse 工作空间包含以下资源: 项目 文件 文件夹 项目启动时一般可以设置工作空间,你可以将其设置为默认工作空间,下次启动后无需再配置: 工作空 ...

  10. jquery取值赋值

    ("#A").val("1") id为A的值就是1了 jQuery中都这样,赋值的时候作为参数传给函数,和单纯的js有区别,像 $("#A" ...