Hdu 1007 最近点对
题目链接
Quoit Design
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 29547 Accepted Submission(s): 7741Problem DescriptionHave you ever played quoit in a playground? Quoit is a game in which flat rings are pitched at some toys, with all the toys encircled awarded.
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.
InputThe input consists of several test cases. For each case, the first line contains an integer N (2 <= N <= 100,000), the total number of toys in the field. Then N lines follow, each contains a pair of (x, y) which are the coordinates of a toy. The input is terminated by N = 0.OutputFor each test case, print in one line the radius of the ring required by the Cyberground manager, accurate up to 2 decimal places.Sample Input2
0 0
1 1
2
1 1
1 1
3
-1.5 0
0 0
0 1.5
0Sample Output0.71
0.00
0.75
/*************************************************************************
> File Name: 1007.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年06月10日 星期二 19时15分21秒
> Propose:
************************************************************************/ #include <cmath>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; #define INF (1000000000.0)
#define MAX_N (100010)
//#define X first
//#define Y second
//#define min(x, y) ((x) < (y) ? (x) : (y))
//typedef pair<double, double> pii;
struct pii {
double X, Y;
}; int n;
pii A[MAX_N], b[MAX_N]; double
min(double x, double y) {
return x < y ? x : y;
} bool
compare_x(pii a, pii b) {
return a.X < b.X;
} bool
compare_y(pii a, pii b) {
return a.Y < b.Y;
} double
get_dist(pii a, pii b) {
return sqrt((a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y));
} double
closest_pair(int low, int high) {
//if (high == low) return INF;
if (high - low == ) return get_dist(A[low], A[high]);
if (high - low == ) {
double d = get_dist(A[low], A[low+]);
d = min(d, get_dist(A[low], A[high]));
d = min(d, get_dist(A[low+], A[high]));
return d;
}
int m = (low + high) / ;
double x = A[m].X;
double d = min(closest_pair(low, m), closest_pair(m+, high)); // (1) int len = ;
for (int i = low; i <= high; i++) {
if (fabs(A[i].X - x) < d) {
b[len++] = A[i];
}
}
sort(b, b + len, compare_y);
for (int i = ; i < len; i++) {
for (int j = i+; j < len; j++) {
double dx = b[j].X - b[i].X;
double dy = b[j].Y - b[i].Y;
if (dy >= d) break;
d = min(d, sqrt(dx * dx + dy * dy));
}
} return d;
} void
solve() {
sort(A, A + n, compare_x);
printf("%.2f\n", closest_pair(, n - ) * 0.5);
} int
main(void) {
while (scanf("%d", &n) && n) {
for (int i = ; i < n; i++)
scanf("%lf %lf", &A[i].X, &A[i].Y); solve();
} return ;
}
Hdu 1007 最近点对的更多相关文章
- hdu 1007最近点对问题
先说下题意,很简单,给n个点的坐标,求距离最近的一对点之间距离的一半.第一行是一个数n表示有n个点,接下来n行是n个点的x坐标和y坐标,实数. 这个题目其实就是求最近点对的距离.主要思想就是分治.先把 ...
- zoj 2107&&hdu 1007最近点对问题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1107 Quoit Design Time Limit: 5 Seconds ...
- hdu 1007 最近点对问题(Splay解法)
为什么要写这个题..经典啊,当然,别以为我用分治做的,不过主要思想还是那神奇的六个点共存(一个h*2h的矩形中最多能放下多少个点使得两两距离不超过h) 其实我是在这里看到的 http://commun ...
- 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 Quoit Design Time Limit: 10000/5000 MS (Java/Oth ...
- 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个点,问最近的两个点之间的距离的一半是多少. 思路:用分治做.把整体分为左右两个部分,那么 ...
- HDU 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 ...
随机推荐
- [转]WPF中的动画
WPF中的动画 周银辉 动画无疑是WP ...
- JZOJ P5829 HZOI 20190801 A string 线段树
JZOJ P5829 A. string 题面:https://www.cnblogs.com/Juve/articles/11286476.html 考场上想起了排序这道题:https://www. ...
- python冒泡排序算法的实现代码
python冒泡排序算法的实现代码 这篇文章主要介绍了python冒泡排序算法的实现代码,大家参考使用 1.算法描述: (1)共循环 n-1 次 (2)每次循环中,如果 前面的数大于后面的数,就交换 ...
- 【Redis安装】部署与基本配置 --基于Mac和Linux
Redis安装与部署[基于Mac和Linux] 一.Redis简介 基于内存的Key-Value高性能NoSQL数据库 二.Redis下载和解压 进入官网下载最新版的Redis,目前是5.0.0,这个 ...
- Windows下shell神器
想找一个可以在Windows平台玩命令行的东西,不想装虚拟机搞linux,所以找到两个神器 如何升级Babun中的Git Babun中默认已经集成Git,只是有可能不是最新的版本 如果只是更新Babu ...
- Django-rest Framework(四)
序列化模块时rest-framework的很重要的组成部分 rest-framework序列化模块(核心) 一. 为什么要使用序列化组件? 后台的数据多以后台的对象存在,经过序列化后,就可以格式化 ...
- mongodb+nodejs 增删查的demo
1.启动数据库 启动完成后显示 端口号是27017 2.创建数据库 创建一个名为mydb的数据库 3.先查询一下当然的用户,再新增一个 4.创建数据表,查询所有的表 db.createCollec ...
- Size Balanced Tree(节点大小平衡树)
定义 SBT也是一种自平衡二叉查找树,它的平衡原理是每棵树的大小不小于其兄弟树的子树的大小 即size(x->l)$\ge$size(x->r->l),size(x->r-&g ...
- Django项目:CRM(客户关系管理系统)--23--15PerfectCRM实现King_admin多条件过滤
登陆密码设置参考 http://www.cnblogs.com/ujq3/p/8553784.html list_filter = ('source','consultant','consult_co ...
- Centos 设置时区
参考网址: http://jingyan.baidu.com/article/636f38bb268a82d6b84610bd.html //打开设置 tzselect //选择 )Asia → )c ...