[HDU1007]Quoit Design


题目描述 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
Description


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 Description


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


数据范围及提示 Data Size &
Hint

 

之前的一些废话:是时候准备会考了。。

题解:求最近点对。首先把平面划分成两个部分,递归求出两个部分的答案为ans,然后,把离分割线距离小于ans/2的点一左一右算距离更新ans.

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
typedef long long LL;
#define mem(a,b) memset(a,b,sizeof(a))
typedef pair<int,int> PII;
const int maxn=100010;
const double oo=2147483647;
struct Point
{
    double x,y;
    Point() {}
    Point(double _1,double _2):x(_1),y(_2){}
    bool operator < (const Point &s)const
    {
        if(x==s.x)return y<s.y;
        return x<s.x;
    }
}p[maxn];
int n;double x,y;
double dis(double a,double b,double c,double d){
    return sqrt((c-a)*(c-a)+(d-b)*(d-b));
}
double mdis(int l,int r)
{
    if(l==r)return 0;
    if(l+1==r)return dis(p[l].x,p[l].y,p[r].x,p[r].y);
    double ret=oo;
    int mid=(l+r)>>1;
    ret=min(mdis(l,mid),mdis(mid,r));
    for(int i=mid-1;i>=l && p[mid].x-p[i].x<ret;i--)
        for(int j=mid+1;j<=r && p[j].x-p[mid].x<ret && fabs(p[i].y-p[j].y)<ret;j++)
            ret=min(ret,dis(p[i].x,p[i].y,p[j].x,p[j].y));
    return ret;
}
int main()
{
    while(scanf("%d",&n)!=EOF && n)
    {
        for(int i=0;i<n;i++)scanf("%lf%lf",&x,&y),p[i]=Point(x,y);
        sort(p,p+n);
        printf("%.2lf\n",mdis(0,n-1)/2);
        for(int i=0;i<n;i++)p[i]=Point(0,0);
    }
    return 0;
}

总结:

时间: 2024-10-17 20:10:51

[HDU1007]Quoit Design的相关文章

HDU1007 Quoit Design 【分治】

Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 30505    Accepted Submission(s): 8017 Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat

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

Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 30919 Accepted Submission(s): 8120 Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings

Quoit Design(hdu1007)

---恢复内容开始--- 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

HDU 1007 Quoit Design

Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 130 Accepted Submission(s): 72   Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings a

HDU 1007 Quoit Design (分治)

Quoit Design 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 ri

Quoit Design

Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 46340    Accepted Submission(s): 12084这题可以分治: 首先按照x方向排序,然后分别对 两边求最短距离. 然后按照y排序,统计距离分割点-d 和+d之间的点,算了,忘了. 但是可以直接排序,然后枚举相邻三个点之间到距离.这三个点

ZOJ - 2107 Quoit Design [分治]

题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17751 题目描述:求最近点对 题目分析:分治,(nlogn): 为什么,第二轮按排序:http://noalgo.info/793.html 代码: //problem: zoj 2107 Quoit Design //author: ACsorry //result: Yes #include<iostream> #include<cstdio>

hdu 1007 Quoit Design 分治求最近点对

Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 29344    Accepted Submission(s): 7688 Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat

分治 [HDU 1007] Quoit Design

Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 33577    Accepted Submission(s): 8800 Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat