首页 > 其他 > 详细

喷水装置

时间:2019-09-20 16:34:36      阅读:97      评论:0      收藏:0      [点我收藏+]

题目描述

思路

代码

#include <cstdio>
#include <cmath>

int n, L, W, t, att, ans;
double w;
struct Node {
    double a, b;
} arr[15006], tmp;
inline void read(int &x) {
    int s = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
    x = s * f;
}
inline void write(int x) {
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
void qsort(int L, int R) {
    int l = L, r = R;
    double mid = arr[l + r >> 1].a;
    while (l < r) {
        while (arr[l].a < mid) l++;
        while (arr[r].a > mid) r--;
        if (l <= r) {
            tmp = arr[l];
            arr[l] = arr[r];
            arr[r] = tmp;
            l++, r--;
        }
    }
    if (l < R) qsort(l, R);
    if (L < r) qsort(L, r);
}
int main() {
    read(t);
    while (t--) {
        ans = 0, att = 0;
        read(n), read(L), read(W);
        double w = W / 2.0, ww = w * w, wx;
        
        for (int i = 1, a, b; i <= n; ++i) {
            read(a), read(b);
            if (b <= w) continue;
            wx = sqrt(b * b - ww);
            arr[++att].a = a - wx;
            arr[att].b = a + wx;
        }
        qsort(1, att);
        double ta = 0.0, tb = 0.0, prea = 0, preb;
        while (ta < L) {
            tb = ta;
            for (int i = prea + 1; i <= att; ++i) {
                if (arr[i].a <= ta && arr[i].b > tb) {
                    tb = arr[i].b;
                    preb = i;
                } 
            }
            ans++;
            if (prea == preb) break;
            ta = tb, prea = preb;
        }
        if (ta >= L) write(ans), puts("");
        else puts("-1");
    }
    return 0;
}

喷水装置

原文:https://www.cnblogs.com/liuzz-20180701/p/11556999.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!