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 ...
随机推荐
- 【赛时总结】◇赛时·VI◇ Atcoder ABC-104
◇赛时·VI◇ ABC-104 ◆??? 莫名爆炸……ABC都AK不了 QwQ C题竟然沦落到卡数据的地步:D题没有思路,直接放弃 ⋋( ◕ ∧ ◕ )⋌ ◆ 题目&解析 ◇A题◇ Rated ...
- cncert阅读报告
信息安全阅读报告 Problem 1: 国家计算机网络应急技术处理协调中心(简称“国家互联网应急中心”,英文缩写为“CNCERT”或“CNCERT/CC”)作为我国非政府层面网络安全应急体系核心技术协 ...
- 安装阿里云版Linux云服务器,配置软件
1. 购买域名 2. 购买云服务器ecs 3. 远程访问云服务器并装上Java环境和必备软件 3.1安装远程访问工具 3.2 jdk环境配置 3.3 Mysql依赖关系 重新配置MySQL的远程 ...
- vue笔记v-bind
把message的信息绑定给title,运行出来的结果是<span title="you loaded this page on +Mon Nov 21 2016 18:28:38 G ...
- PHP的IMAP函数
imap_8bit -转换的8位字符串的引用,打印字符串 imap_alerts -返回所有的I MAP邮件警报已经发生 imap_append -附加了一系列的信息到指定邮箱 imap_base64 ...
- strak组件(9):关键字搜索
效果图: 在列表视图函数增加搜索功能. 新增函数 def get_search_list(self) 钩子方法,获取搜索条件 一.strak组件 strak/service/core_func.py ...
- VIM配置IDE
转载于:https://blog.csdn.net/andre617/article/details/53496490#%E8%84%9A%E6%B3%A8 由于YCM需要vim支持python,需要 ...
- Android 本应用数据清除管理器DataCleanManager
1.整体分析 1.1.源代码先给出了,可以直接Copy. /** * 本应用数据清除管理器 */ public class DataCleanManager { /** * * 清除本应用内部缓存(/ ...
- PHP.TP框架下商品项目的优化1-时间插件、鼠标所在行高亮、布局规划页面
1.优化搜索表单中按时间搜索的功能 添加一个时间插件datetimepicker,在lst.html中,注意要导入jquery.min.js,此处从前文的在线编辑器中导入 <!-- 导入 --& ...
- 【Power of Two】cpp
题目: Given an integer, write a function to determine if it is a power of two. 代码: class Solution { pu ...