题目链接: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.
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.
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.
3 0 1 1 0 1 1
0.50000000000000000000
7 2 -3 -2 -3 3 0 -3 -1 1 -2 2 -2 -1 0
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;
}