题意
给点集
P
,求
题解
先说说正解:
先不考虑三点共线
注意到任何一个三角形都有一个角
∈(π/3,π)
(因为内角和
=π
),所以我们枚举第
i
个点作为这个角的顶点,把其他点极角排序,用一个单调队列维护距离的最小值即可,具体实现详见代码1。
注意三点共线的问题,那么这个“三角形”一定有一个角
复杂度
O(n2logn)
然后,当我知道能bitset水过时,我内心是崩溃的。。。
不妨把
n2
个距离从大到小排序,那么每次我取一条边,边的两个顶点为
u,v
,连接
u,v
,如果
u,v
已经通过某一个
w
<script type="math/tex" id="MathJax-Element-1048">w</script>连接的话,就构成了一个“三角形”(包括三点共线),那么就搞定了呀~(类似地,弦图可以类似地搞)
两个启示是:
1. 遇到三角形的时候,可以考虑其内角和一定,利用平均数原理可以得到一个不等式,从而缩减枚举量
2. Bitset在处理三角形时有奇效。。。
code
正常解法:
// 日了狗!竟然有三点共线
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
const double eps=1e-8;
const double PI=acos(-1.0);
const int maxn=6010;
struct Point{
int x,y;
Point(){}
Point(int x,int y):x(x),y(y){}
};
Point operator + (const Point &A, const Point &B) { return Point(A.x+B.x, A.y+B.y); }
Point operator - (const Point &A, const Point &B) { return Point(A.x-B.x, A.y-B.y); }
double Dot(const Point &A, const Point &B) { return (double)A.x*B.x + (double)A.y*B.y; }
double Length(const Point &A) { return sqrt(Dot(A, A)); }
Point p[maxn];
struct Line {
Point A, B, v;
double ang;
Line() { }
Line(Point A, Point B): A(A), B(B) { v = B-A; ang = atan2(v.y, v.x); }
// ax + by + c > 0
bool operator < (const Line &A) const { return ang < A.ang; }
};
int n;
Line L[maxn];
int Q[maxn]; int Ql,Qr;
int main(){
// freopen("K.in","r",stdin);
scanf("%d",&n);
for(int i=0;i<n;++i){
int x,y; scanf("%d%d",&x,&y);
p[i]=Point(x,y);
}
double res=0.0;
for(int o=0;o<n;++o){
int m=0;
for(int i=0;i<n;++i)if(i!=o) { L[m++]=Line(p[o],p[i]); }
sort(L,L+m);
for(int i=0;i<m;++i) L[i+m]=L[i], L[i+m].ang+=2*PI;
Ql=0,Qr=0;
int Qp=0;
for(int l=0,r=0;l<m;++l){
for(;Qp<2*m&&L[Qp].ang<L[l].ang+PI+eps;){
while(Qr-Ql>=1 && Length(L[Q[Qr-1]].v)<Length(L[Qp].v)) --Qr;
Q[Qr++]=Qp++;
}
for(;r<2*m&&L[r].ang-L[l].ang<PI/3;++r);
while(Qr-Ql>=1&&Q[Ql]<r) ++Ql;
if (Qr-Ql>=1)res=max(res,min(Length(L[l].v),Length(L[Q[Ql]].v)));
}
// printf("%.20lf\n",res/2);
}
printf("%.20lf\n",res/2);
// for(;;);
return 0;
}
bitset:
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
using namespace std;
const int maxn=3010;
struct Point{
int x,y;
Point(){}
Point(int x,int y):x(x),y(y){}
};
Point operator + (const Point &A, const Point &B) { return Point(A.x+B.x, A.y+B.y); }
Point operator - (const Point &A, const Point &B) { return Point(A.x-B.x, A.y-B.y); }
double Dot(const Point &A, const Point &B) { return (double)A.x*B.x + (double)A.y*B.y; }
double Length(const Point &A) { return sqrt(Dot(A, A)); }
Point p[maxn];
bitset<maxn> f[maxn];
pair<double, pair<int, int> > A[maxn*maxn];
int AN;
int n;
int main(){
// freopen("K.in","r",stdin);
scanf("%d",&n);
for(int i=0;i<n;++i){
int x,y; scanf("%d%d",&x,&y);
p[i]=Point(x,y);
}
AN=0;
for(int i=0;i<n;++i)
for(int j=0;j<n;++j)
A[AN++]=make_pair(Length(p[j]-p[i]),make_pair(i,j));
sort(A,A+AN);
double res=0.0;
for(int i=AN-1;i>=0;--i){
int x=A[i].second.first, y=A[i].second.second;
f[x].set(y);
f[y].set(x);
if((f[x]&f[y]).count()>0){
res=A[i].first/2;
break;
}
}
printf("%.20lf\n", res);
// for(;;);
return 0;
}