---恢复内容开始---

Quoit Design

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

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
思路:分治;
最近点对模板题;

这个题目其实就是求最近点对的距离。《算法导论》上有详细讲解,王晓东的书上也有代码。主要思想就是分治。先把n个点按x坐标排序,然后求左边n/2个和右边n/2个的最近距离,最后合并。

合并要重点说一下,比较麻烦。

首先,假设点是n个,编号为1到n。我们要分治求,则找一个中间的编号m,先求出1到m点的最近距离设为d1,还有m+1到n的最近距离设为d2。这里的点需要按x坐标的顺序排好,并且假设这些点中,没有2点在同一个位置。(若有,则直接最小距离为0了)。

然后,令d为d1, d2中较小的那个点。如果说最近点对中的两点都在1-m集合中,或者m+1到n集合中,则d就是最小距离了。但是还有可能的是最近点对中的两点分属这两个集合,所以我们必须先检测一下这种情况是否会存在,若存在,则把这个最近点对的距离记录下来,去更新d。这样我们就可以得道最小的距离d了。

关键是要去检测最近点对,理论上每个点都要和对面集合的点匹配一次,那效率还是不能满足我们的要求。所以这里要优化。怎么优化呢?考虑一下,假如以我们所选的分割点m为界,如果某一点的横坐标到点m的横坐标的绝对值超过d1并且超过d2,那么这个点到m点的距离必然超过d1和d2中的小者,所以这个点到对方集合的任意点的距离必然不是所有点中最小的。(上面的是噢别人的,链接http://blog.csdn.net/allenjy123/article/details/6627751)

 1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<queue>
5 #include<string.h>
6 #include<stdlib.h>
7 #include<set>
8 #include<math.h>
9 using namespace std;
10 const double INF=1e12;
11 typedef struct pp
12 {
13 double x;
14 double y;
15 } ss;
16 bool cmp_x(pp p,pp q)
17 {
18 return p.x < q.x;
19 }
20 bool cmp_y(pp p,pp q)
21 {
22 return p.y < q.y;
23 }
24 double slove(pp *s,int m);
25 ss node[1000005];
26 int main(void)
27 {
28 int i,j;
29 int n;int __ca=0;
30 while(scanf("%d",&n),n != 0)
31 {
32 for(i = 0; i < n; i++)
33 {
34 scanf("%lf %lf",&node[i].x,&node[i].y);
35 }
36 sort(node,node+n,cmp_x);
37 double ask = slove(node,n);
38 printf("%.2f\n",ask/2);
39 }
40 return 0;
41 }
42 double slove(ss *s,int m)
43 {
44 if(m <= 1)return INF;
45 int mid = m/2;
46 double d;int x = s[mid].x;
47 d = min(slove(s,mid),slove(s+mid,m-mid));
48 inplace_merge(s,s+mid,s+m,cmp_y);
49 int i,j;
50 vector<ss>vec;
51 for(i = 0;i < m; i++)
52 {
53 if(fabs(s[i].x-x) >= d)
54 continue;
55 int cn = vec.size();
56 for(j = 0;j < cn ;j++)
57 {
58 double dx = fabs(s[i].x - vec[cn-j-1].x);
59 double dy = fabs(s[i].y - vec[cn-j-1].y);
60 if(dy >= d)
61 break;
62 d = min(d,sqrt(dx*dx+dy*dy));
63 }
64 vec.push_back(s[i]);
65 }
66 return d;
67 }

Quoit Design(hdu1007)的更多相关文章

  1. poj 1007 Quoit Design(分治)

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

  2. hdu 1007 Quoit Design(分治)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007 题意:给出n个点求最短的两点间距离除以2. 题解:简单的分治. 其实分治就和二分很像二分的写df ...

  3. 激光雷达Lidar Architecture and Lidar Design(上)

    激光雷达Lidar Architecture and Lidar Design(上) 介绍 激光雷达结构: 基本条件 构型和基本布置 激光雷达设计: 基本思想和基本原则 总结 介绍 激光雷达结构是激光 ...

  4. Quoit Design(最近点对+分治)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007 Quoit Design Time Limit: 10000/5000 MS (Java/Oth ...

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

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

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

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

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

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

  8. hdu 1007 Quoit Design(平面最近点对)

    题意:求平面最近点对之间的距离 解:首先可以想到枚举的方法,枚举i,枚举j算点i和点j之间的距离,时间复杂度O(n2). 如果采用分治的思想,如果我们知道左半边点对答案d1,和右半边点的答案d2,如何 ...

  9. Material Design (四),AppBarLayout的使用

    前言  AppBarLayout,顾名知意.就是用来给AppBar布局的容器,是LinearLayout的子类.而AppBar就包括我们通常所知道的ActionBar,Toolbar. AppBarL ...

随机推荐

  1. Linux实现批量添加用户及随机密码小脚本

    通过chpasswd命令可实现迅速为用户批量设置密码     实例:写一个脚本,实现批量添加20个用户user1-20,密码为用户名和后面跟5个随机字符 #!/bin/sh # 思路:通过for循环, ...

  2. Tikz绘制形似万花尺的图片

    初中时意外发现数学课本上有这么一个好玩的图 大概就是把两条相等线段A.B分为10个小段并在点上标序号,A线段1点连B线段9点,2点连8点,依次类推. 假设有这么一个框架图 按照第一张图的方式进一步绘图 ...

  3. C#表格,表格信息、GridView使用。

    page: <%@ Control Language="C#" AutoEventWireup="true" CodeFile="test1.a ...

  4. Oracle中的null与空字符串''的区别

    含义解释:问:什么是NULL?答:在我们不知道具体有什么数据的时候,也即未知,可以用NULL,我们称它为空,ORACLE中,含有空值的表列长度为零.ORACLE允许任何一种数据类型的字段为空,除了以下 ...

  5. fastJson序列化

    在pojo实体中有map<String,Object>的属性,有个key是user它存储在数据库中是用户的id数组,而在aop里会对这个属性做用户详细信息查询并重新put给user.在做J ...

  6. ebs 初始化登陆

    BEGIN fnd_global.APPS_INITIALIZE(user_id => youruesr_id, esp_id => yourresp_id, resp_appl_id = ...

  7. Linux学习 - 网络命令

    一.write 1 功能 给指定在线用户发信息,以Ctrl + D保存结束 2 语法 write  <用户名>  [信息] 二.wall(write all) 1 功能 给所有在线用户发送 ...

  8. 初始化Linux数据盘、磁盘分区、挂载磁盘(fdisk)

    1.操作场景 2.前提条件 3.划分分区并挂载磁盘 4.设置开机自动挂载磁盘分区 1.操作场景 本文以云服务器的操作系统为"CentOS 7.4 64位"为例,采用fdisk分区工 ...

  9. js中获取url参数

    function getUrlVars() { var vars = [], hash; var hashes = window.location.href.slice(window.location ...

  10. lucene索引的增、删、改

    package com.hope.lucene;import org.apache.lucene.document.Document;import org.apache.lucene.document ...