BZOJ 4140: 共点圆加强版 [二进制分组]

本文介绍了一种在线处理几何问题的方法,特别是对于涉及多个圆及其与特定点位置关系的问题。通过对点的位置进行数学变换,利用凸包算法和二分搜索技巧来高效地确定一个点是否位于一系列给定圆的内部。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description

要求支持两个操作:

  • 0 x y加入一个圆心为(x,y)的过原点的圆。
  • 1 x y询问点(x,y)是否在所有圆内部。

强制在线。

Solution

二进制分组都不会啊
一个点(x0,y0)合法就等价于

(x0xi)2+(y0yi)2x2i+y2i
化简得到了
yx0y0x+x202y0+y02
这就是一次函数的形式。
就相当于是所有点都要在这条直线的上方。
在凸包上用这条直线逼近,直到有焦点,再判断一下截距的大小就好了。
实现的话,就是二分凸包上的斜率。
这道题要求强制在线。
二进制分组!
eps打错了好久,就跟弱智一样。
#include <bits/stdc++.h>
using namespace std;

const int N = 510010;
const int M = 30;
const double eps = 1e-8;

struct Point {
    double x, y;
    Point (double _x = 0, double _y = 0):x(_x), y(_y) {}
    inline friend Point operator -(const Point &a, const Point &b) {
        return Point(a.x - b.x, a.y - b.y);
    }
    inline friend double operator *(const Point &a, const Point &b) {
        return a.x * b.y - b.x * a.y;
    }
    inline friend double operator /(const Point &a, const Point &b) {
        return (a.y - b.y) / (a.x - b.x);
    }
    inline friend bool operator <(const Point &a, const Point &b) {
        return a.x == b.x ? a.y < b.y : a.x < b.x;
    }
};
Point In;
int n, opt, lim, cnt, online;
double x, y;
Point sta[N];
struct Group {
    vector<Point> a, b;
    int lim, size, usd;
    inline void ConvexHull(void) {
        b.clear(); size = 0; usd = 1;
        sort(a.begin(), a.end());
        sta[++size] = a[0];
        for (int i = 1; i < lim; i++) {
            while (size > 1 && (sta[size] - sta[size - 1]) * (a[i] - sta[size]) - eps < 0) --size;
            sta[++size] = a[i];
        }
        for (int i = 1; i <= size; i++) b.push_back(sta[i]);
    }
    inline bool Query(double x0, double y0, double k) {
        int L = 1, R = size - 1, Mid, Pos = 0;
        while (L <= R) {
            Mid = (L + R) >> 1;
            if (k > b[Mid] / b[Mid - 1]) {
                L = Mid + 1; Pos = Mid;
            } else R = Mid - 1;
        }
        return x0 * x0 + y0 * y0 - 2.0 * x0 * b[Pos].x - 2.0 * y0 * b[Pos].y - eps < 0;
    }
};
Group B[M];

inline void MakeGroup(Point &x, int pos) {
    int cnt = 0; B[pos].a.clear();
    B[pos].a.push_back(x);
    for (int i = 1; i < pos; i++) {
        B[i].usd = 0;
        for (int j = 0; j < B[i].lim; j++)
            B[pos].a.push_back(B[i].a[j]);
    }
    B[pos].usd = 1; B[pos].ConvexHull();
}
inline void Insert(Point &x) {
    for (int i = 1; i <= lim; i++)
        if (!B[i].usd) return MakeGroup(x, i);
}
inline bool Query(double x0, double y0) {
    double k = -x0 / y0;
    bool flag = (In.y != 0);
    for (int i = 1; i <= lim; i++)
        if (B[i].usd) flag &= B[i].Query(x0, y0, k);
    return flag;
}

int main(void) {
    freopen("1.in", "r", stdin);
    scanf("%d", &n); lim = 25;
    for (int i = 1; i <= lim; i++)
        B[i].lim = 1 << (i - 1);
    for (int i = 1; i <= n; i++) {
        scanf("%d%lf%lf", &opt, &x, &y);
        x += online; y += online;
        if (opt) {
            if (Query(x, y)) {
                puts("Yes"); online++;
            } else puts("No");
        } else {
            Insert(In = Point(x, y));
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值