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 ...
随机推荐
- c语言学习笔记 - 枚举类型
今天学习了c语言的枚举类型的使用,可能是PHP里没使用过,开始看的时候还是觉得有点怪,后来做了下例子才理解,这里做个笔记记录一下. #include <stdio.h> enum anim ...
- autoreleasing的用法介绍:
在c/c++,objective-c内存管理中有一条是:谁分配谁释放. __autoreleasing则可以使对像延迟释放.比如你想传一个未初始化地对像引用到一个方法当中,在此方法中实始化此对像,那么 ...
- typeof, offsetof, container_of宏
container_of宏实现如下: #define container_of(ptr, type, member) ({ \ )->member ) *__mptr = (ptr); \ (t ...
- Ceisum官方教程3 -- 空间数据可视化
原文地址:https://cesiumjs.org/tutorials/Visualizing-Spatial-Data/ 这篇教程教你如何使用Cesium的Entity API去绘制空间数据,如点, ...
- PAT甲级——A1033 To Fill or Not to Fill
With highways available, driving a car from Hangzhou to any other city is easy. But since the tank c ...
- springmvc 串口读写 基于win7使用txrx netbeans jdk1.8 maven的
引入 <dependency> <groupId>org.rxtx</groupId> <artifactId>rxtx</artifactId& ...
- Leetcode144. Binary Tree Preorder Traversal二叉树的前序遍历
给定一个二叉树,返回它的 前序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,2,3] 进阶: 递归算法很简单,你可以通过迭代算法完成吗? 递归: class S ...
- Effective Modern C++ 条款1:理解模板型别推导
成百上千的程序员都在向函数模板传递实参,并拿到了完全满意的结果,而这些程序员中却有很多对这些函数使用的型别是如何被推导出的过程连最模糊的描述都讲不出来. 但是当模板型别推导规则应用于auto语境时,它 ...
- 1.Js 点击控件区域之外隐藏控件
1.限制对象可以是 div 或者from 2.添加calss =stopProhide 3.需要添加jquery 类库 示例: $("#form_Query").click(fun ...
- loj6402 校门外的树(dp,多项式求逆)
https://loj.ac/problem/6402 庆祝一下,,,第一个我自己做出来的,,,多项式的题(没办法,我太弱 虽然用了2个小时才想出来,但这毕竟是0的突破…… 首先声明,虽然我写的题解很 ...