hdu 1007 Quoit Design (最近点对问题)
Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25335 Accepted Submission(s): 6716
In the field of Cyberground, the position of each toy is fixed, and the ring is carefully designed so it can only encircle one toy at a time. On the other hand, to make the game look more attractive, the ring is designed to have the largest radius. Given a configuration of the field, you are supposed to find the radius of such a ring.
Assume that all the toys are points on a plane. A point is encircled by the ring if the distance between the point and the center of the ring is strictly less than the radius of the ring. If two toys are placed at the same point, the radius of the ring is considered to be 0.
0 0
1 1
2
1 1
1 1
3
-1.5 0
0 0
0 1.5
0
0.00
0.75
//1468MS 2288K 1378 B G++
/* 题意;
给出n个点,求最近的两个点的距离的一般 最近点对:
要用到分治的思想做,是时间复杂度为O(nlgn),直接求会超时
最近点对问题在很多算法书和资料上都有讲到,主要思想是分治。 注意一点: 用C的 qsort排序一直TLE,表示有点无力.. */
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#define N 100005
using namespace std;
struct node{
double x,y;
}p[N];
int a[N];
int n;
double cmpx(node a,node b)
{
return a.x<b.x;
}
double cmpy(int a,int b)
{
return p[a].y<p[b].y;
}
inline double Max(double a,double b)
{
return a>b?a:b;
}
inline double Min(double a,double b)
{
return a<b?a:b;
}
inline double Dis(node a,node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double find(int l,int r)
{
if(l==r) return 0x7ffffff;
if(r==l+) return Dis(p[l],p[r]);
if(r==l+) return Min(Dis(p[l],p[r]),Min(Dis(p[l],p[l+]),Dis(p[l+],p[r])));
int mid=(l+r)>>;
double d=Min(find(l,mid),find(mid+,r));
int cnt=;
for(int i=l;i<=r;i++){
if(p[i].x>=p[mid].x-d && p[i].x<=p[mid].x+d)
a[cnt++]=i;
}
sort(a,a+cnt,cmpy);
for(int i=;i<cnt;i++){
for(int j=i+;j<cnt;j++){
if(p[a[j]].y-p[a[i]].y>=d) break;
d=Min(d,Dis(p[a[i]],p[a[j]]));
}
}
return d;
}
int main(void)
{
while(scanf("%d",&n)!=EOF)
{
if(n==) break;
for(int i=;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
sort(p,p+n,cmpx);
printf("%.2lf\n",find(,n-)/);
}
return ;
}
hdu 1007 Quoit Design (最近点对问题)的更多相关文章
- HDU 1007 Quoit Design最近点对( 分治法)
题意: 给出平面上的n个点,问任意点对之间的最短距离是多少? 思路: 先将所有点按照x坐标排序,用二分法将n个点一分为二个部分,递归下去直到剩下两或一个点.对于一个部分,左右部分的答案分别都知道,那么 ...
- 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 ...
- 杭电OJ——1007 Quoit Design(最近点对问题)
Quoit Design Problem Description Have you ever played quoit in a playground? Quoit is a game in whic ...
- HDU 1007 Quoit Design 平面内最近点对
http://acm.hdu.edu.cn/showproblem.php?pid=1007 上半年在人人上看到过这个题,当时就知道用分治但是没有仔细想... 今年多校又出了这个...于是学习了一下平 ...
- 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(分治法求最近点对)
大致题意:给N个点,求最近点对的距离 d :输出:r = d/2. // Time 2093 ms; Memory 1812 K #include<iostream> #include&l ...
随机推荐
- Java打印金字塔问题
Java打印金字塔问题 public class 金字塔问题 { // //普通金字塔 // public static void main(String[] args) { // //先打印4层 / ...
- nodejs 发送邮件(阿里云)
1.下载 模块 2. 编辑文件 var nodemailer = require('nodemailer'); var sendEmail = function(emailinfo,callbac ...
- thymeleaf单选回显,多选回显,选回显,下拉默认选中第一个
//默认选中第一个<input type ="radio" name="repaymentType" th:each ="repaymentTy ...
- 路由器基础配置之rip
我们将以上面的拓扑图进行实验,用rip协议来进行实验,目的是实现三台不同网段的pc机之间实现互相通信 首先为pc机配置好ip地址和网关,配置完IP地址后在配置路由器 router1: enable 进 ...
- scrapy--dytt(电影天堂)
喜欢看电影的小伙伴,如果想看新的电影,然后没去看电影院看,没有正确的获得好的方法,大家就可以在电影天堂里进行下载.这里给大家提供一种思路. 1.dytt.py # -*- coding: utf-8 ...
- 课时16.HTML-XHTML-HTML5区别(了解)
简而言之 HTML语法非常宽松容错性强: XHTML更为严格,它要求标签必须小写,必须严格闭合,标签中的属性必须使用引号引起等等. HTML5是HTML的下一个版本所以除了非常宽松容错性强以外,还增加 ...
- 访问远程mysql数据库,出现报错,显示“1130 - Host'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server“
在使用Navicat for MySQl访问远程mysql数据库,出现报错,显示“1130 - Host'xxx.xxx.xxx.xxx' is not allowed to connect to t ...
- PHP 二维数组按某一个键值排序
一.前言 在某个项目中,需要读取某个文件夹下的所有文件,在本地的 Windows 环境下时,读取出来的二维数组的文件名称和在 Windows 文件夹的文件排序一致, 但是项目上线后,环境为 Linux ...
- photoshop入门笔记1:PS的快捷键
PS部分快捷键: 1.魔棒的作用:比较快捷的抠图工具,对于一些分界线比较明显的图像,通过魔棒工具可以很快速的将图像抠出,魔棒的作用是可以知道你点击的那个地方的颜色,并自动获取附近区域相同的颜色,使它们 ...
- 16,Flask-Migrate
终于到了Flask-Migrate,之前在学习Flask-SQLAlchemy的时候,Flask支持 makemigration / migrate 吗? 答案在这里该诉你,如果你同时拥有两个三方组件 ...