HDU1007:Quoit Design——题解
http://acm.hdu.edu.cn/showproblem.php?pid=1007
题目大意:给n个点,求点对最短距离/2.
——————————————————————
平面分治裸题。
暂时还不想讲为什么这么做。
所以原理暂割。
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef double dl;
const dl INF=1e20;
const int N=;
struct node{
dl x;
dl y;
}p[N],a[N],b[N],c[N];
bool cmp(node A,node B){
return A.x<B.x;
}
inline dl dis(int i,int j){
return sqrt(pow(b[i].x-c[j].x,)+pow(b[i].y-c[j].y,));
}
dl solve(int l,int r){
if(l>=r)return INF;
int mid=(l+r)>>;
dl x0=(p[mid].x+p[mid+].x)/2.0;
dl d=min(solve(l,mid),solve(mid+,r));
int l1=l,r1=mid+,bnum=,cnum=;
for(int i=l;i<=r;i++){
if(l1<=mid&&(r1>r||p[l1].y<p[r1].y)){
a[i]=p[l1++];
if(x0-d<a[i].x)b[++bnum]=a[i];
}else{
a[i]=p[r1++];
if(a[i].x<x0+d)c[++cnum]=a[i];
}
}
for(int i=l;i<=r;i++)p[i]=a[i]; for(int i=,j=;i<=bnum||j<=cnum;){
if(i<=bnum&&(j>cnum||b[i].y<c[j].y)){
for(int k=j-;k>=;k--){
if(b[i].y-d>=c[k].y)break;
d=min(d,dis(i,k));
}
i++;
}else{
for(int k=i-;k>=;k--){
if(c[j].y-d>=b[k].y)break;
d=min(d,dis(k,j));
}
j++;
}
}
return d;
}
int main(){
int n;
while(scanf("%d",&n)!=EOF&&n){
for(int i=;i<=n;i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
}
sort(p+,p+n+,cmp);
printf("%.2f\n",solve(,n)/2.0);
}
return ;
}
HDU1007:Quoit Design——题解的更多相关文章
- HDU1007 Quoit Design 【分治】
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU1007 Quoit Design掷环游戏
Quoit Design 看懂题意以后发现就是找平面最近点对间距离除以2. 平面上最近点对是经典的分治,我的解析 直接上代码 #include<bits/stdc++.h> using n ...
- Hdoj 1007 Quoit Design 题解
Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings ...
- (hdu1007)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 简单裸题,测测模板,G++速度快了不少,应该是编译的时候对比C++优化了不少.. //STATU ...
- HDU1007.Quoit Design
-- 点我 -- 题目大意 :给你一堆点,求一个最小圆能够覆盖两个点的半径(最近两点距离的一半): 最多100000个点,暴力即O(n^2)会超时,考虑二分,先求左边最短距离dl,右边dr, 和一个点 ...
- hdu 1007 Quoit Design 题解
原题地址 题目大意 查询平面内最近点对的距离,输出距离的一半. 暴力做法 枚举每一个点对的距离直接判断,时间复杂度是 $ O(n^2) $,对于这题来说会超时. 那么我们考虑去优化这一个过程,我们在求 ...
- ACM-计算几何之Quoit Design——hdu1007 zoj2107
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- Quoit Design(hdu1007)最近点对问题。模版哦!
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
随机推荐
- leetcode笔记11 First Unique Character in a String
题目描述: Given a string, find the first non-repeating character in it and return it's index. If it does ...
- 两个有序数组合并成一个有序数组(要求时间复杂度为O(n))
面试题: 怎样把两个有序数组合并成有序数组呢 逻辑步骤: 1.假设两个数组为A和B 2.A和B都是从小到大的顺序进行排列 ** 1.我们可以直接比较两个数组的首元素,哪个小就把这个小元素放入可变数组. ...
- Java开发工程师(Web方向) - 01.Java Web开发入门 - 第1章.Web应用开发概述
第1章--Web应用开发概述 Web应用开发概述 浏览器-服务器架构(BS-architecture) browser/ App ---- request ----> server ...
- python 中的reload(sys)
import sys reload(sys) sys.setdefaultencoding('utf-8') #python2中的使用方法 #重新载入 sys 模块,并设置默认编码为 utf8 & ...
- js for循环实例
1.求1-100的寄数和? //2.奇数求和 var ppt=0 for(var i=1;i<=100;i+=2){ ppt+=i } 2.求1-100的偶数和 var num=0 for(va ...
- 82. Single Number [easy]
Description Given 2*n + 1 numbers, every numbers occurs twice except one, find it. Example Given [1, ...
- 【Linux 运维】 安装PHP工具Composer
一.安装PHP 由于Composer是 PHP 用来管理依赖(dependency)关系的工具.你可以在自己的项目中声明所依赖的外部工具库(libraries),Composer 会帮你安装这些依赖的 ...
- Skype for Business Server 方案
方案说明: 高可用性的配置屏蔽了单点故障,使得当一个服务器节点失效时,另外的可用的节点能够进行服务的接管.可伸缩性的配置可以保证当即时沟通平台的使用用户增加时,该平台应该具有良好的可伸缩性,能非常方便 ...
- [模板]非递归线段树(zkw的变异版本)
类似于zkw,但空间只用两倍,zkw要4倍. 链接 可以下传标记,打熟后很好码. #include <set> #include <cmath> #include <cs ...
- 今日头条 2018 AI Camp 6 月 2 日在线笔试编程题第一道——最大连续区间和扩展
题目 给出一个长度为 n 的数组a1.a2.....ana1.a2.....an,请找出在所有连续区间 中,区间和最大同时这个区间 0 的个数小于等于 3 个,输出这个区间和. 输入描述: 第一行一个 ...