CodeForces333E Summer Earnings

题目链接:http://codeforces.com/contest/333/problem/E

题面:

Many schoolchildren look for a job for the summer, and one day, when Gerald was still a schoolboy, he also decided to work in the summer. But as Gerald was quite an unusual schoolboy, he found quite unusual work. A certain Company agreed to pay him a certain sum of money if he draws them three identical circles on a plane. The circles must not interfere with each other (but they may touch each other). He can choose the centers of the circles only from the n options granted by the Company. He is free to choose the radius of the circles himself (all three radiuses must be equal), but please note that the larger the radius is, the more he gets paid.

Help Gerald earn as much as possible.

Input

The first line contains a single integer n — the number of centers (3 ≤ n ≤ 3000). The following n lines each contain two integers xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of potential circle centers, provided by the Company.

All given points are distinct.

Output

Print a single real number — maximum possible radius of circles. The answer will be accepted if its relative or absolute error doesn't exceed 10 - 6.

Examples
Input
Copy
3
0 1
1 0
1 1
Output
0.50000000000000000000
Input
Copy
7
2 -3
-2 -3
3 0
-3 -1
1 -2
2 -2
-1 0
Output
1.58113883008418980000

题意:给出N个点,找到其中3个点,以任意半径画圆,但3个圆不能相交(可以相切,见样例1)。

题解:显然可以枚举C(N,3),然后构成三角形最短边的一半最大值就是答案。会TLE, 我们换种想法。

           首先O(N^2)算出所有线段,问题等价于找到AB, BC, AC三条线,求max{min{AB,BC,AC}}。我们得到线段之后从大到小排序,bitset<N>a[N],表示当前有某个点,那么当我们加入某条线段时,两个点有我A,B,如果a[A],a[B]可以由交集就说明存在C点,构成一个三角形,又因为我们是从大到小枚举的,找到第一个就是最优解。复杂度(N^3 / 32),可以通过。

#include <bits/stdc++.h>

using namespace std;
#define SZ(X) ((int)X.size())
#define mp make_pair
#define pb push_back
#define RALL(X) X.rbegin(),X.rend()
#define ALL(X) X.begin(),X.end()

using ll = long long ;
using ld = long double ;

const int N = 3010;

int sqr(int a) {return a*a;}

struct Point
{
    int x, y;
}p[N];
struct Seg
{
    int u, v, d;
    bool operator < (const Seg& s) const {
        return d > s.d;
    }
}seg[N*N];
bitset<N>a[N];


int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 1;i <= n;i ++) scanf("%d%d",&p[i].x,&p[i].y);
    int m = 0;
    for(int i = 1;i <= n;i ++) {
        for(int j = i + 1;j <= n;j ++) {
            seg[++m] = {i, j, sqr((p[i].x-p[j].x)) + sqr((p[i].y-p[j].y))};
        }
    }
    sort(seg+1, seg+1+m);
    for(int i = 1;i <= m;i ++) {
        int t1 = seg[i].u;
        int t2 = seg[i].v;
        if((a[t1]&a[t2]).count()) {
            return !printf("%.12f\n",sqrt(seg[i].d) / 2.0);
        }
        a[t1].set(t2);
        a[t2].set(t1);
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值