Quoit Design

看懂题意以后发现就是找平面最近点对间距离除以2.

平面上最近点对是经典的分治,我的解析

直接上代码

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1000005;
const double inf=1e12;
struct node{
double x,y;
}p[N];
bool cmp(node a,node b)
{
if(a.x==b.x)return a.y<b.y;
return a.x<b.x;
}
bool cmp2(int a,int b)
{
return p[a].y<p[b].y;
}
double dist(int a,int b){return sqrt((p[a].x-p[b].x)*(p[a].x-p[b].x)+(p[a].y-p[b].y)*(p[a].y-p[b].y));}
int n,a[N];
double msort(int l,int r)
{
double d=inf;
if(l==r)return d;
if(l==r-1)return dist(l,r);
int mid=l+r>>1;
double d1=msort(l,mid);
double d2=msort(mid+1,r);
d=min(d1,d2);
int cnt=0;
for(int i=l;i<=r;i++)
if(fabs(p[i].x-p[mid].x)<=d)a[++cnt]=i;
sort(a+1,a+cnt+1,cmp2);
for(int i=1;i<=cnt;i++)
{
for(int j=i+1;j<=cnt&&fabs(p[a[i]].y-p[a[j]].y)<d;j++)
{
d=min(d,dist(a[i],a[j]));
}
}
return d;
}
signed main()
{
while(scanf("%lld",&n)!=EOF)
{
if(n==0)return 0;
for(int i=1;i<=n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
sort(p+1,p+n+1,cmp);
printf("%.2lf\n",msort(1,n)/2);
}
}

HDU1007 Quoit Design掷环游戏的更多相关文章

  1. HDU1007 Quoit Design 【分治】

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

  2. (hdu1007)Quoit Design,求最近点对

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

  3. HDU-1007 Quoit Design 平面最近点对

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007 简单裸题,测测模板,G++速度快了不少,应该是编译的时候对比C++优化了不少.. //STATU ...

  4. HDU1007.Quoit Design

    -- 点我 -- 题目大意 :给你一堆点,求一个最小圆能够覆盖两个点的半径(最近两点距离的一半): 最多100000个点,暴力即O(n^2)会超时,考虑二分,先求左边最短距离dl,右边dr, 和一个点 ...

  5. ACM-计算几何之Quoit Design——hdu1007 zoj2107

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

  6. Quoit Design(hdu1007)最近点对问题。模版哦!

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

  7. Quoit Design(hdu1007)

    ---恢复内容开始--- Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

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

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

  9. hdu1443(约瑟夫环游戏的原理 用链表过的)

    Problem Description The Joseph's problem is notoriously known. For those who are not familiar with t ...

随机推荐

  1. FFmpeg——AVCodec,AVCodecContext,AVCodecParameters 辨析

    先贴上雷神的一张FFmpeg关键结构体之间的关系图: 再看雷神的分析: 每个AVStream存储一个视频/音频流的相关数据: 每个AVStream对应一个AVCodecContext,存储该视频/音频 ...

  2. R-CNN算法中NMS的具体做法

    假设有20类,2000个建议框,最后输出向量维数2000*20,则每列对应一类,一行是各个建议框的得分,NMS算法步骤如下: ① 对2000×20维矩阵中每列按从大到小进行排序: ② 从每列最大的得分 ...

  3. elasticsearch mapping简单介绍

    这两天一直在看elasticsearch相关的内容,看到mapping这一块,就折腾了下. 一般情况下,我们不需要对elasticsearch的mapping进行设置,但如果希望对索引使用自定义的管理 ...

  4. 302重定向之后,session中存储的值没了

    302重定向之后,session中存储的值没了

  5. DeepLearning算法文章

    算法源码: learn_dl : https://github.com/hanbt/learn_dl rnn-from-scratch : https://github.com/pangolulu/r ...

  6. css 盒子模型简介

    盒子模型 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...

  7. ROS学习笔记10-写一个简单的订阅者和发布者(C++版本)

    本文档来源于:http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29 写发布者节点如前所述,节点是连接到RO ...

  8. VUE 父子组件之间通信传值 props和 $emit

    1.父组件传值给子组件 $props,子组件传值给父组件 $emit 父组件          <div id="app" >               <tr ...

  9. Day3-P - Matrix POJ3685

    Given a N × N matrix A, whose element in the i-th row and j-th column Aij is an number that equals i ...

  10. 「SCOI2005」栅栏

    传送门 Luogu 解题思路 我们有很显然的这样一条贪心思路: 首先满足长度短的木板,因为如果可以满足长的也肯定可以满足短的,而且可能满足更多. 那么我们就会有这样的思路:枚举一条木板由哪条木板切割而 ...