跳到正文

题解

题解:P16393 [ECUSTPC 2026 Spring] 聚光灯下

_CuteRalsei_约 4 分钟
原文
文章信息与版本

文章信息

发布
2026年5月2日
收录
2026年5月10日
更新
2026年10月14日
篇幅
约 4 分钟
题目
P16393

版本

  1. v2当前
  2. v1

其实难度就是橙吧。

我们考虑二分答案,设答案为 dd。

蓝色长度就是 dd。关于计算角度 α\alpha 和 β\beta,只需要反着用余弦定理即可。

C++
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;
}

怎么判断是否有解呢?

我们把所有这种蓝色部分构成的夹角区间放在一起,检查有没有交集就行了。

坑点:需要特殊判断 >2π>2\pi 和 <0<0 的点。

C++
#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;
}

警示后人。

原文
存档评论5 条抓取于