其实难度就是橙吧。
我们考虑二分答案,设答案为 。
蓝色长度就是 。关于计算角度 和 ,只需要反着用余弦定理即可。
double angle(double a,double b,double c){
double ang=acos((b*b+c*c-a*a)/(2*b*c));
return isnan(ang)?-1:ang;
}怎么判断是否有解呢?
我们把所有这种蓝色部分构成的夹角区间放在一起,检查有没有交集就行了。
坑点:需要特殊判断 和 的点。
#include <bits/stdc++.h>
using namespace std;
#define double long double
#define int long long
#ifdef double
#define acos acosl
#define asin asinl
#define atan2 atan2l
#define fabs fabsl
#define sqrt sqrtl
#endif
const double PI=acos(-1);// 不能用 M_PI!
#define M_PI PI
#define d(x,y) (sqrt(1ll*x*x+1ll*y*y))
double A(double ang){
if(ang>M_PI*2)return ang-M_PI*2;
if(ang<0)return ang+M_PI*2;
return ang;
}
constexpr double eps=1e-10;
vector<pair<int,int>> v;
bool eq(double a,double b){
return fabs(a-b)<=eps;
}
double angle(double a,double b,double c){
double ang=acos((b*b+c*c-a*a)/(2*b*c));
return isnan(ang)?-1:ang;
}
bool check(double d){
vector<pair<double,double>> ran;//ranges
for(auto [x,y]:v){
double r=d(x,y),ang=angle(r,r,d),k=A(atan2(y,x));
if(ang<0)return 0;
ran.push_back({k-ang,k+ang});
}
double jl,jr,ql,qr;//jl,jr交集 ql,qr 其实是跨 0,2pi 边界的补集
jl=ql=0,jr=qr=M_PI*2;
for(auto [l,r]:ran){
if(l<0||r>M_PI*2){
l=A(l);
r=A(r);
ql=max(ql,l);
qr=min(qr,r);
}
else{
jl=max(jl,l);
jr=min(jr,r);
}
}
if(jl>jr)return 0;
return ql<jr||qr>jl;
}
signed main()
{
int T;
cin>>T;
while(T--){
int n,ma_x=0,ma_y=0;
cin>>n;
v.clear();
while(n--){
int x,y;
cin>>x>>y;
v.push_back({x,y});
}
double l=0,r=3e5;
while(!eq(l,r)){
double mid=(l+r)/2;
if(check(mid))l=mid;
else r=mid;
}
printf("%.9Lf\n",l);
}
return 0;
}警示后人。
