P4288 [SHOI2014] 信号增幅仪

· · 题解

思路:

考虑伸缩变换旋转,首先将坐标轴逆时针旋转 \theta 度,即相当于将每个点绕原点逆时针 \theta 度。

同时椭圆的长轴系数为 b,那么将每个点 (x, y) \to (\frac{x}{b}, y),容易发现此时椭圆上的点在新的坐标系下为一个圆,且这个圆的半径为短轴长。

于是跑一次随机增量的最小圆覆盖即可,平均时间复杂度为 O(N)。

完整代码:

 #include<bits/stdc++.h>
#define lowbit(x) x & (-x)
#define ls(k) k << 1
#define rs(k) k << 1 | 1
#define fi first
#define se second
#define add(x, y) ((x + y >= mod) ? (x + y - mod) : (x + y))
#define dec(x, y) ((x - y < 0) ? (x - y + mod) : (x - y))
#define ctz(x) __builtin_ctz(x)
#define popcnt(x) __builtin_popcount(x)
#define open(s1, s2) freopen(s1, "r", stdin), freopen(s2, "w", stdout);
using namespace std;
typedef __int128 __;
typedef double db;
typedef unsigned long long ull;
typedef long long ll;
bool Begin;
const int N = 5e4 + 10;
const db eps = 1e-9, pi = acos(-1);
inline ll read(){
    ll x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9'){
        if(c == '-')
          f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9'){
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }
    return x * f;
}
inline void write(ll x){
    if(x < 0){
        putchar('-');
        x = -x;
    }
    if(x > 9)
      write(x / 10);
    putchar(x % 10 + '0');
}
int n;
db a, b;
class Point{
public:
    db x, y;
    inline Point(db _x = 0, db _y = 0){
        x = _x;
        y = _y;
    }
    inline bool operator<(const Point&rhs)const{
        if(x == rhs.x)
          return y < rhs.y;
        return x < rhs.x;
    }
    inline void Read(){
        scanf("%lf%lf", &x, &y);
    }
    inline bool operator==(const Point &rhs)const{
        return (x == rhs.x) && (y == rhs.y);
    }
    inline Point operator-(const Point &rhs)const{
        return {x - rhs.x, y - rhs.y};
    }
    inline Point operator+(const Point &rhs)const{
        return {x + rhs.x, y + rhs.y};
    }
    inline Point operator*(const db &k)const{
        return {x * k, y * k};
    }
    inline Point operator/(const db &k)const{
        return {x / k, y / k};
    }
    inline friend Point rev(Point a){
        return {-a.y, a.x};
    }
    inline friend Point rotate(Point a, db theta){
        db coss = cos(theta), sinn = sin(theta);
//      cerr << coss << ' ' << sinn << ' ' << theta << ' ' << a.x * sinn + a.y * coss << '\n';
        return {a.x * coss - a.y * sinn, a.x * sinn + a.y * coss};
    }
    inline friend db dis(Point a, Point b){
        return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
    }
    inline friend db dot(Point a, Point b){
        return a.x * b.x + a.y * b.y;
    }   
    inline friend db cross(Point a, Point b){
        return a.x * b.y - a.y * b.x;
    }   
    inline friend db cross(Point a, Point b, Point c){
        return cross(b - a, c - a);
    }
    inline db operator*(const Point &rhs)const{
        return cross(*this, rhs);
    }
    inline friend Point getPoint(Point a, Point u, Point b, Point v){
        db t = ((a - b) * v) / (v * u);
        return a + (u * t);
    }
    inline friend pair<Point, Point> midLine(Point a, Point b){
        return {(a + b) / 2, rev(b - a)};
    }
}p[N];
class Circle{
public:
    Point u;
    db r;
    inline Circle(Point _u = 0, db _r = 0){
        u = _u;
        r = _r;
    }
};  
inline Circle cover(Point a, Point b){
    return {(a + b) / 2, dis(a, b) / 2};
}
inline Circle cover(Point a, Point b, Point c){
    auto u = midLine(a, b), v = midLine(a, c);
    auto t = getPoint(u.fi, u.se, v.fi, v.se);
    return {t, dis(a, t)};
}
inline Circle Smallest_circle(Point a[], int n){
    Circle ans = {a[1], 0};
    for(int i = 2; i <= n; ++i){
        if(ans.r < dis(a[i], ans.u)){
            ans = {a[i], 0};
            for(int j = 1; j < i; ++j){
                if(ans.r < dis(a[j], ans.u)){
                    ans = cover(a[i], a[j]);
                    for(int k = 1; k < j; ++k)
                      if(ans.r < dis(a[k], ans.u))
                        ans = cover(a[i], a[j], a[k]);
                }
            }
        }
    }
    return ans;
}
mt19937 R(time(0));
bool End;
signed main(){
//  freopen("1.in", "r", stdin);
    n = read();
    for(int i = 1; i <= n; ++i)
      p[i].Read();
    a = read(), b = read();
    for(int i = 1; i <= n; ++i){
        p[i] = rotate(p[i], -a / 180 * pi);
        p[i].x /= b;
    }
    shuffle(p + 1, p + n + 1, R);
//  cerr << midLine(p[1], p[2]).fi.x << ' ' << midLine(p[1], p[2]).fi.y << ' ' << midLine(p[1], p[2]).se.x << ' ' << midLine(p[1], p[2]).se.y << '\n';
    auto ans = Smallest_circle(p, n);
    printf("%.3lf", ans.r);
    cerr << '\n' << abs(&Begin - &End) / 1048576 << "MB";
    return 0;
}