HDU1007

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

这个题的题干虽然这么长但是实际上就是说输入一大堆点,从里边找出两个距离最短的来,算出他俩距离的一半。
我也没看懂这段题干的意思,看别人博客我才明白的啥意思

这个题肯定不能用也点一个点的求啦百分百超时的…
那可是10W….
只要是这么大数据量的必然是NlogN以下的复杂度
不然写一次死一次
….
然后这个题看上去其实就是排序的思想啦,我作为一个新人对这些思想并不熟练,从排序n²降到nlogn这个方法我能想到这个也许也是用的分治….

真的写不出来….
然后百度一个代码看明白了思路自己写了一份

这个题说真的分治分治的看起来不是很彻底,因为就算分治完了,你也要把所有的值进行对比,这里分治的作用是求出一个范围来,你在这个范围之上进行选择,不符合条件的直接break
….
这个范围怎么确定呢,比函数返回值ans大的全部都是不要!
这样就可以了….
比如选x的时候就要在中间那个点左边减去ans,右边加上ans,超过这个范围的肯定都不对
至于为啥不对呢,这里就不形式化的证明了
举几个典型例子~
也许你会想万一ans在mid左边的ans以外咋办这种问题..
根本不现实啊,就算真的在那边之前的分治的ans也求得就是他了....
右边同理
现在就只剩下跨越两边的情况了啊!!!
既然跨越两边了,那么比中间那个ans范围大的有啥用啊.....
黑人问好脸.jpg
...
另外根据学长说的吗,卡输入的题都不是好题
这个题就不是好题..........
cin会超时
只能用scanf
我这份代码967ms
稍微有点危险,不过我也算个新人就先这样吧
~
下面上代码

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
struct ma
{
    double x, y;
};
ma map[100005];
ma*bok[100005];
ma*bop[100005];
bool cmpx(ma*a, ma*b) { return a->x < b->x; }
bool cmpy(ma*a, ma*b) { return a->y < b->y; }
double min(double a, double b) { return a<b ? a : b; }
double dis(ma *a, ma* b)
{
    return sqrt((a->x - b->x)*(a->x - b->x) + (a->y - b->y)*(a->y - b->y));
}
double ds(int s, int e)
{
    int mid = (s + e) / 2;
    if (s + 1 == e)return dis(bok[s], bok[e]);
    if (s + 2 == e)return min(dis(bok[s], bok[s + 1]), min(dis(bok[s], bok[e]), dis(bok[s + 1], bok[e])));
    double ans = min(ds(s, mid), ds(mid + 1, e));
    int cnt = 0;
    for (int a = s;a <= e;a++)
    {
        if (bok[a]->x >= bok[mid]->x - ans&&bok[a]->x <= bok[mid]->x + ans)
            bop[cnt++] = bok[a];
    }
    sort(bop, bop+cnt, cmpy);
    for (int a = 0;a < cnt;a++)
    {
        for (int b = a + 1;b < cnt;b++)
        {
            if (bop[b]->y - bop[a]->y >= ans)break;
            ans = min(ans, dis(bop[a], bop[b]));
        }
    }
    return ans;
}
int main()
{
    int n;
    while (cin >> n)
    {
        if (n == 0)break;
        for (int a =0 ;a < n;a++)
        {
            scanf("%lf%lf", &map[a].x, &map[a].y);
            bok[a] = &map[a];
        }
        sort(bok, bok+n, cmpx);
        double sdsd = ds(0, n-1);
        printf("%.2lf\n", sdsd / 2);
    }
    return 0;
}

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值