• UVA 10382 Watering Grass


    UVA_10382

        喷水装置能否覆盖草坪,其实只取决于图中每个圆蓝色部分能否将草坪覆盖,这样我们就将问题转化成了有若干线段,求覆盖一个指定区间最少要多少条线段。

    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    #define MAXN 10010
    const double eps = 1e-10;
    int N, M;
    double L, W;
    struct Seg
    {
        double x, y;
        bool operator < (const Seg &t) const
        {
            return x < t.x;
        }
    }seg[MAXN];
    int dcmp(double x)
    {
        return (x > eps) - (x < -eps);
    }
    double sqr(double x)
    {
        return x * x;
    }
    void input()
    {
        M = 0;
        for(int i = 0; i < N; i ++)
        {
            double p, r;
            scanf("%lf%lf", &p, &r);
            if(dcmp(2 * r - W) <= 0) continue;
            double l = sqrt(sqr(r) - sqr(W * 0.5));
            seg[M].x = p - l, seg[M].y = p + l, ++ M;
        }
        std::sort(seg, seg + M);
    }
    int process()
    {
        int cnt = 0;
        double x = 0, y = 0;
        for(int i = 0; i < M; i ++)
        {
            if(dcmp(seg[i].x - x) > 0)
            {
                if(dcmp(seg[i].x - y) > 0) return -1;
                ++ cnt, x = y;
                if(dcmp(x - L) >= 0) return cnt;
            }
            y = std::max(y, seg[i].y);
        }
        if(dcmp(y - L) < 0) return -1;
        return cnt + 1;
    }
    int main()
    {
        while(scanf("%d%lf%lf", &N, &L, &W) == 3)
        {
            input();
            printf("%d\n", process());
        }
        return 0;
    }
  • 相关阅读:
    关于java和jvm的思考
    java之try、catch、finally
    Microsoft SQLServer有四种系统数据库
    HDU 5087
    uva639 暴力、回溯
    uva127
    uva 131
    洛谷 P2580 于是他错误的点名开始了
    字典树(trie)
    HTML学习笔记
  • 原文地址:https://www.cnblogs.com/staginner/p/2760341.html
Copyright © 2020-2023  润新知