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 ...
随机推荐
- 安装虚拟机以及ubuntu
近期要用到linux,所以开始学习.想要在这里记录自己的学习之路 1.安装虚拟机以及装ubuntu系统 虚拟机就相当于一台电脑,电脑里得有系统,我们选择了ubuntu作为操作系统. 安装看下面的博客操 ...
- 一个只有十行的精简MVVM框架(上篇)
本文来自网易云社区. 前言 MVVM模式相信做前端的人都不陌生,去网上搜MVVM,会出现一大堆关于MVVM模式的博文,但是这些博文大多都只是用图片和文字来进行抽象的概念讲解,对于刚接触MVVM模式的新 ...
- 「日常训练」Jin Yong’s Wukong Ranking List(HihoCoder-1870)
题意与分析 2018ICPC北京站A题. 题意是这样的,给定若干人的武力值大小(A B的意思是A比B厉害),问到第几行会出现矛盾. 这题不能出现思维定势,看到矛盾就是矛盾并查集--A>B.A&g ...
- cf#516A. Make a triangle!(三角形)
http://codeforces.com/contest/1064/problem/A 题意:给出三角形的三条边,问要让他组成三角形需要增加多少长度 题解:规律:如果给出的三条边不能组成三角形,那答 ...
- 加油吧 骚年QAQ
本随笔文章,由个人博客(鸟不拉屎)转移至博客园 写于:2017 年 11 月 08 日 原地址:https://niaobulashi.com/archives/fighting.html --- 想 ...
- 407. Plus One【LintCode java】
Description Given a non-negative number represented as an array of digits, plus one to the number. T ...
- 洪水!(Flooded! ACM/ICPC World Final 1999,UVa815)
题目描述:竞赛入门经典的习题4-10 解题思路:1.把各个网格想象成一个数组 2.排序 3.雨水总体积去铺满 //太懒了只写了求海拔 #include <stdio.h> #define ...
- hive使用spark引擎的几种情况
使用spark引擎查询hive有以下几种方式:1>使用spark-sql(spark sql cli)2>使用spark-thrift提交查询sql3>使用hive on spark ...
- Linux 150命令之 文件和目录操作命令 cd pwd cp mv touch
cd 切换目录 cd 目录 [root@mysql ~]# cd / [root@mysql /]# ls application bin class dev home lib64 media nfs ...
- ffmpeg实现mjpeg摄像头的采集-预览-拍照
摄像头输出是mjpeg格式的,需要实现在线预览功能,然后实现拍照功能 1.可以设置采集图像的分辨率,预览分辨率为640*480,可以自定义 2.ctrl+\ 拍照,ctrl+c 退出 void tes ...