题目:

问题描述 :

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.

输入:

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.

输出:

For each test case, print in one line the radius of the ring required by the Cyberground manager, accurate up to 2 decimal places.

样例输入:

2
0 0
1 1
2
1 1
1 1
3
-1.5 0
0 0
0 1.5
0

样例输出:

0.71
0.00
0.75

题解:

心得:

平面分治经典模板题···核心思想就是按xy坐标排序后分成左右两边分治··复杂度nlogn;

代码:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<cctype>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
const int N=1e+;
struct point
{
double x;
double y;
}p[N],px[N];
bool compx(point a,point b)
{
return a.x<b.x;
}
bool compy(point a,point b)
{
return a.y<b.y;
}
inline double dis(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int n;
double work(int l,int r)
{
double ans;
if(l+==r) return dis(p[l],p[r]);
if(l+==r) return min(dis(p[l],p[l+]),min(dis(p[l],p[r]),dis(p[l+],p[r])));
int mid=(l+r)/;
ans=min(work(l,mid),work(mid+,r));
int cnt=;
for(int i=l;i<=r;i++)
{
if(p[i].x>=p[mid].x-ans&&p[i].x<=p[mid].x+ans)
px[++cnt]=p[i];
}
sort(px+,px+cnt+,compy);
for(int i=;i<=cnt;i++)
for(int j=i+;j<=cnt;j++)
{
if(px[j].y-px[i].y>=ans)
break;
ans=min(ans,dis(px[i],px[j]));
}
return ans;
}
int main()
{
freopen("a.in","r",stdin);
while(scanf("%d",&n)!=EOF)
{
if(n==) break;
for(int i=;i<=n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
sort(p+,p+n+,compx);
printf("%.2lf\n",work(,n)/);
}
return ;
}

算法复习——平面分治(hud1007)的更多相关文章

  1. 算法复习——cdq分治

    题目: Description 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义一朵花A比另一朵花B要 ...

  2. 算法复习——序列分治(ssoj光荣的梦想)

    题目: 题目描述 Prince对他在这片大陆上维护的秩序感到满意,于是决定启程离开艾泽拉斯.在他动身之前,Prince决定赋予King_Bette最强大的能量以守护世界.保卫这里的平衡与和谐.在那个时 ...

  3. C#冒泡算法复习

    C#冒泡算法复习 冒泡算法的意思:每一趟找到一个最小或最大的数放到最后面,比较总数的n-1次(因为比较是2个双双比较的) 第一层循环表示进行比较的次数,总共要比较(数的)-1次 (因为比较是2个双双比 ...

  4. 计算几何 平面最近点对 nlogn分治算法 求平面中距离最近的两点

    平面最近点对,即平面中距离最近的两点 分治算法: int SOLVE(int left,int right)//求解点集中区间[left,right]中的最近点对 { double ans; //an ...

  5. C语言排序算法复习

    排序算法有很多种,这里在复习和分析的基础上,做一个自己的总结: 首先要知道有哪些排序算法,google一下,有云C语言7大经典排序算法(也有8大).主要包括冒泡排序,快速排序,选择排序,插入排序,希尔 ...

  6. 【从零学习经典算法系列】分治策略实例——高速排序(QuickSort)

    在前面的博文(http://blog.csdn.net/jasonding1354/article/details/37736555)中介绍了作为分治策略的经典实例,即归并排序.并给出了递归形式和循环 ...

  7. Luogu 1429 平面最近点对 | 平面分治

    Luogu 1429 平面最近点对 题目描述 给定平面上n个点,找出其中的一对点的距离,使得在这n个点的所有点对中,该距离为所有点对中最小的 输入输出格式 输入格式: 第一行:n:2≤n≤200000 ...

  8. KMP算法复习【+继续学习】

    离NOIP还剩12天,本蒟蒻开始准备复习了. 先来个KMP[似乎我并没有写过KMP的blog] KMP KMP算法是解决字符串匹配问题的一个算法,主要是单对单的字符串匹配加速,时间复杂度O(m + n ...

  9. 算法复习周------“动态规划之‘最长公共子序列’”&&《计蒜课》---最长公共子串题解

    问题描述: 这个问题其实很容易理解.就是给你两个序列X={x1,x2,x3......xm} Y={y1,y2,y3......ym},要求找出X和Y的一个最长的公共子序列. 例:Xi={A, B, ...

随机推荐

  1. vue+element ui项目总结点(四)零散细节概念巩固如vue父组件调用子组件的方法、拷贝数据、数组置空问题 等

    vue config下面的index.js配置host: '0.0.0.0',共享ip (假设你的电脑启动了这个服务我电脑一样可以启动)-------------------------------- ...

  2. watchguard 软件工程师内部招聘!

    作为watchguard正式员工,现发布公司最近的招聘信息,待遇优厚,请符合条件的朋友和我联系并将简历发给我,我会尽早联系公司人力部门. 我的邮件:daibao91888@163.com 博客:htt ...

  3. Adding other views to UIButton

    Q: I want to add some views to UIButton, for example multiple UILabels, UIImages etc. One I add thos ...

  4. shell批量转换iOS和Android图标

    icon_ios.sh #!/bin/sh convert icon-1024.png -resize 180x180 icon-180@3x.png convert icon-1024.png -r ...

  5. Clusterware 和 RAC 中的域名解析的配置校验和检查 (文档 ID 1945838.1)

    适用于: Oracle Database - Enterprise Edition - 版本 10.1.0.2 到 12.1.0.1 [发行版 10.1 到 12.1]Oracle Database ...

  6. 使用js将后台返回的数据转换成树形结构

    将类似如下数据转换成树形的数据: [ { id: 1, name: '1', }, { id: 2, name: '1-1', parentId: 1 }, { id: 3, name: '1-1-1 ...

  7. windows使用文件服务器搭建Git服务器

    背景: 1.windows下搭建git服务器. 2.git服务器搭建在局域网文件共享区中. 3.没有复杂的权限控制,文件共享区都有访问权限. 步骤: 1.文件共享区中创建git远程仓库. 2.本地克隆 ...

  8. 文件操作-cd

    cd命令是linux实际使用当中另一个非常重要的命令,本文就为大家介绍下Linux中cd命令的用法. 转载自 https://www.cnblogs.com/waitig/p/5880719.html ...

  9. 守护进程,互斥锁,IPC,生产者与消费者模型

    守护进程: b 进程守护 a进程,当a进程执行完毕时,b进程会跟着立马结束 守护进程用途: 如果父进程结束了,子进程无需运行了,就可以将子进程设置为父进程的守护进程 例如我们qq视频聊天时,当我们退出 ...

  10. 我的第一个ajax脚本

    代码如下 //创建XMLHttpRequest对象 var xmlHttp=null; function creatXMLHttp(){ try{ xmlHttp = new XMLHttpReque ...