HDU 1007 Quoit Design | 平面分治
暂鸽
#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 | 平面分治的更多相关文章
- 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个点求最短的两点间距离除以2. 题解:简单的分治. 其实分治就和二分很像二分的写df ...
- 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(经典最近点对问题)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1007 Quoit Design Time Limit: 10000/5000 MS (Java/Oth ...
- 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 分治求最近点对
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 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 (最近点对问题)
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- poj 1007 Quoit Design(分治)
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
随机推荐
- Leetcode463. Island Perimeter
题目 给定一个包含 0 和 1 的二维网格地图,其中 1 表示陆地 0 表示水域. 网格中的格子水平和垂直方向相连(对角线方向不相连).整个网格被水完全包围,但其中恰好有一个岛屿(或者说,一个或多个表 ...
- BZOJ1202: [HNOI2005]狡猾的商人(带权并查集)
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4577 Solved: 2249[Submit][Status][Discuss] Descript ...
- 【经典问题】bzoj2957: 楼房重建
经典问题:动态维护上升子序列长度 进阶问题:[经典问题]#176. 栈 Description 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无 ...
- Linux相关知识
1.设置代理 sudo vi /etc/apt/apt.conf Acquire::http::Proxy "http://proxy_address:8080/"; 2.生成 s ...
- selenium webdriver 移动到某个位置,滚动到某个位置
https://blog.csdn.net/xiaosongbk/article/details/70231564
- Jenkins搭建CI/CD
所需Jenkins插件: Maven Integration pluginPublish Over SSHSSH plugin 1.配置全局工具 配置JDK: 配置Git: 配置maven: 2.创建 ...
- 【linux】【指令】systemctl 指令部分解读
systemctl [OPTIONS...] {COMMAND} ... Query or send control commands to the systemd manager. -h --hel ...
- 【yii】【php】自定义故障代码
实际状态码: 200 操作成功 406 账号密码错误 208 请勿重复操作 401 需登陆验证 405 不容许此方法 409 验证错误
- day1_作业(账户登录检测)
#!/usr/local/bin/python3 # -*- coding:utf-8 -*- f=open('/users/zhangyu/PycharmProjects/s14/day1/Home ...
- ubuntu中使用apt命令安装ipython失败解决方案
在最近使用ubuntu安装ipython时,出现如下报错: 出现这个问题,主要是因为apt还在运行,故解决方案为: 1.找到并且杀掉所有的apt-get 和apt进程 运行下面的命令来生成所有含有 a ...