题目链接

Quoit Design

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 29547    Accepted Submission(s): 7741

Problem Description
Have 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.

Input
The 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.
Output
For each test case, print in one line the radius of the ring required by the Cyberground manager, accurate up to 2 decimal places. 
Sample Input
2
0 0
1 1
2
1 1
1 1
3
-1.5 0
0 0
0 1.5
0
Sample Output
0.71
0.00
0.75
 
计算最小点对的思想是:分治
注意:在下面代码中,如果使用宏定义来定义来替换取小函数min,则TLE。
Accepted Code:
 /*************************************************************************
> 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 最近点对的更多相关文章

  1. hdu 1007最近点对问题

    先说下题意,很简单,给n个点的坐标,求距离最近的一对点之间距离的一半.第一行是一个数n表示有n个点,接下来n行是n个点的x坐标和y坐标,实数. 这个题目其实就是求最近点对的距离.主要思想就是分治.先把 ...

  2. zoj 2107&&hdu 1007最近点对问题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1107 Quoit Design Time Limit: 5 Seconds   ...

  3. hdu 1007 最近点对问题(Splay解法)

    为什么要写这个题..经典啊,当然,别以为我用分治做的,不过主要思想还是那神奇的六个点共存(一个h*2h的矩形中最多能放下多少个点使得两两距离不超过h) 其实我是在这里看到的 http://commun ...

  4. HDU 1007 Quoit Design(二分+浮点数精度控制)

    Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. HDU 1007 Quoit Design(经典最近点对问题)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1007 Quoit Design Time Limit: 10000/5000 MS (Java/Oth ...

  6. HDU 1007 Quoit Design 平面内最近点对

    http://acm.hdu.edu.cn/showproblem.php?pid=1007 上半年在人人上看到过这个题,当时就知道用分治但是没有仔细想... 今年多校又出了这个...于是学习了一下平 ...

  7. HDU 1007:Quoit Design(分治求最近点对)

    http://acm.hdu.edu.cn/showproblem.php?pid=1007 题意:平面上有n个点,问最近的两个点之间的距离的一半是多少. 思路:用分治做.把整体分为左右两个部分,那么 ...

  8. HDU 1007(套圈 最近点对距离)

    题意是求出所给各点中最近点对的距离的一半(背景忽略). 用分治的思想,先根据各点的横坐标进行排序,以中间的点为界,分别求出左边点集的最小距离和右边点集的最小距离,然后开始合并,分别求左右点集中各点与中 ...

  9. hdu 1007 Quoit Design(分治法求最近点对)

    大致题意:给N个点,求最近点对的距离 d :输出:r = d/2. // Time 2093 ms; Memory 1812 K #include<iostream> #include&l ...

  10. HDU 1007 Quoit Design(计算几何の最近点对)

    Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings ...

随机推荐

  1. java虚拟机(十四)--字节码指令

    字节码指令其实是很重要的,在之前学习String等内容,深入到字节码层面很容易找到答案,而不是只是在网上寻找答案,还有可能是错误的. PS:本文基于jdk1.8 首先写个简单的类: public cl ...

  2. webpack配置根据浏览器自动添加css前缀的loader

    1.安装 postcss-loader autoprefixer npm install postcss-loader autoprefixer --save-dev 2.配置webpack.conf ...

  3. sde中的shp数据无法编辑

    最近整理空间数据库时,用sde比较多,发现在编辑sde中的数据时总是出现数据被锁或者是被其他应用程序占用.用了很多方法处理,但不是每个方法都实用.下面讲的是我在删除shp或者给shp增加字段时所遇到的 ...

  4. [jeecms]获取父栏目下的子栏目名称

    [@cms_channel_list parentId='父栏目id'] [#list tag_list as c] <a href="${c.url}">${c.na ...

  5. 60行JavaScript代码俄罗斯方块

    教你看懂网上流传的60行JavaScript代码俄罗斯方块游戏   早就听说网上有人仅仅用60行JavaScript代码写出了一个俄罗斯方块游戏,最近看了看,今天在这篇文章里面我把我做的分析整理一下( ...

  6. docker启动redis设置密码

    docker run --name picker-redis -p 6379:6379 -d redis --requirepass "认证密码"

  7. 11.5 临近csp·道别

    差不多到写这个东西的时候了? 嗯,按今天的日期来算的话,还有不到十天就是csp.感觉对我这种家伙来说应该算是终结了? 放在之前的话肯定会写很多东西的,不过现在大约有点不知道写什么比较合适. 所以只是祝 ...

  8. 设置mysql二进制日志过期时间

    ((none)) > show variables like 'expire_logs_days'; +------------------+-------+ | Variable_name | ...

  9. Ubuntu修改mysql编码格式

    今天在Ubuntu系统上部署了第一个net core的web网站,遇到了mysql入库数据乱码的情况.无奈,ubuntu系统不熟悉,mysql命令不熟悉,只得在网上查找各种资料.还是老规矩,主要参考的 ...

  10. mac vagrant 虚拟机nfs挂载点

    需求:在mac 上安装了虚拟机,虚拟机系统为centos6.5,现在希望讲虚拟机上点目录通过nfs共享给mac使用 下面主要描述通过nfs共享目录给mac调用的过程 过程参考网址: http://ww ...