文章

171

粉丝

165

获赞

73

访问

91.1k

头像
喷水装置 题解:贪心
P802
发布于2026年2月12日 17:22
阅读数 76

#include <bits/stdc++.h>
using namespace std;
int n, cnt, L, h, x, r;
struct node {
    double x, y;
} a[200005];
bool cmp(node a, node b) {
    return a.x < b.x;
}
void read() {
    cnt = 0;
    cin >> n >> L >> h;

    for (int i = 1; i <= n; i++) {
        cin >> x >> r;

        if (r <= h / 2)
            continue;

        cnt++;
        a[cnt].x = x - sqrt(r * r - h * h / 4.0);
        a[cnt].y = x + sqrt(r * r - h * h / 4.0);
    }
}
void solve() {
    double t = 0;
    int ans = 0, bj = 1, i = 1;

    while (t < L) {
        ans++;
        double s = t;

        for (; a[i].x <= s && i <= cnt; i++) {
            if (t < a[i].y)
                t = a[i].y;
        }

        if (t == s && s < L) {
            cout << -1 << endl;
            bj = 0;
            break;
        }
    }

    if (bj)
        cout << ans << endl;
}
in...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发