HDU 1007 Quoit Design(计算几何の最近点对)
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.
题目大意:输出最近点对的距离的一半
思路:分治法,先按X轴排序。然后两边分治算最近距离,设为res,然后按y轴合并,只提取出离中间的点的x的距离不超过res的点,采用7点比较法。
代码(1687MS):
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL; struct Point {
double x, y;
Point() {}
Point(double x, double y): x(x), y(y) {}
void read() {
scanf("%lf%lf", &x, &y);
}
double length() {
return sqrt(x * x + y * y);
}
Point operator - (const Point &rhs) const {
return Point(x - rhs.x, y - rhs.y);
}
}; double dist(const Point &a, const Point &b) {
return (a - b).length();
} bool x_cmp(const Point &a, const Point &b) {
return a.x < b.x;
} bool y_cmp(const Point &a, const Point &b) {
return a.y < b.y;
} const int MAXN = ; Point p[MAXN];
double ans;
int n; double closest_pair(Point *p, int n) {
if(n <= ) return 1e100;
int mid = n / ;
double x = p[mid].x;
double res = min(closest_pair(p, mid), closest_pair(p + mid, n - mid));
inplace_merge(p, p + mid, p + n, y_cmp);
vector<Point> q;
for(int i = ; i < n; ++i) {
if(fabs(p[i].x - x) >= res) continue;
for(vector<Point>::reverse_iterator it = q.rbegin(); it != q.rend(); ++it) {
if(p[i].y - it->y >= res) break;
res = min(res, dist(p[i], *it));
}
q.push_back(p[i]);
}
return res;
} int main() {
while(scanf("%d", &n) != EOF && n) {
for(int i = ; i < n; ++i) p[i].read();
sort(p, p + n, x_cmp);
printf("%.2f\n", closest_pair(p, n) / );
}
}
HDU 1007 Quoit Design(计算几何の最近点对)的更多相关文章
- 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)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 平面内最近点对
http://acm.hdu.edu.cn/showproblem.php?pid=1007 上半年在人人上看到过这个题,当时就知道用分治但是没有仔细想... 今年多校又出了这个...于是学习了一下平 ...
- hdu 1007 Quoit Design(分治法求最近点对)
大致题意:给N个点,求最近点对的距离 d :输出:r = d/2. // Time 2093 ms; Memory 1812 K #include<iostream> #include&l ...
- 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(平面最近点对)
题意:求平面最近点对之间的距离 解:首先可以想到枚举的方法,枚举i,枚举j算点i和点j之间的距离,时间复杂度O(n2). 如果采用分治的思想,如果我们知道左半边点对答案d1,和右半边点的答案d2,如何 ...
随机推荐
- 【算法笔记】B1010 一元多项式求导
1010 一元多项式求导 (25 分) 设计函数求一元多项式的导数.(注:xn(n为整数)的一阶导数为nxn−1.) 输入格式: 以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过 ...
- java中实现多线程的几种方式(简单实现)
一.以下只是简单的实现多线程 1:继承Thread 2:实现 Runnable 3:实现callable 如果需要返回值使用callable,如果不需要返回最好使用runnable,因为继承只能单继承 ...
- 关于Hibernate基于version的乐观锁
刚刚接触SSH框架,虽然可能这个框架已经比较过时了,但是个人认为,SSH作为一个成熟的框架,作为框架的入门还是可以的. 马马虎虎学完了Hibernate的基础,总结一点心得之类的. 学习Hiberna ...
- Python系列之入门篇——python2.7.13安装
Python2.7.13 安装 说明 以下所有操作都基于centos6.9 1. Issue zlib zlib-devel是安装setuptools依赖的模块,需要在安装python之前先安装这两个 ...
- 如何在VMware Fusion中导入windows下的虚拟机
最近换了新款的mbp,因为偷懒,便将之前在windows台式机上的虚拟机搬了过来. 特此记录下搬运过程,方便以后查看. 一 操作过程 安装激活VMware 常规操作,无需赘言 拷贝windows下虚拟 ...
- vue.js使用axios
使用axios的两种调用方式 1.安装axios $ cnpm install axios 2.在vue入口文件main.js中引入(推荐全局引入),或是在当前页面中引入(局部) import axi ...
- 使用 Linux 下的的logrotate进行日志的切割
实际生产中,使用一个log文件来记录所有信息的话,一方面,时间过久,就会占用很大的空间:另一方面,就是一个文件记录对于后期日志的查看非常不利.为了解决查看了一下资料,发现linux里面有一个logro ...
- 搭建Git服务器-SCM-Manager
基于配置简单的原则,先试用一下SCM-Manager http://www.scm-manager.org/ 看主页介绍:Very easy installation 安装简单,配置方便,不需要额外的 ...
- springBoot RabbitMq 转换json序列化
package com.alirm.redis_cache.config.RabbitMQ; import org.springframework.amqp.rabbit.core.RabbitTem ...
- Spark性能优化--开发调优与资源调优
参考: https://tech.meituan.com/spark-tuning-basic.html https://zhuanlan.zhihu.com/p/22024169 一.开发调优 1. ...