zoukankan      html  css  js  c++  java
  • UVA

    题意:有一个矩形,n个圆。已知矩形的长宽和圆的半径,问最少需多少个圆将矩形完全覆盖。

    分析:

    1、首先求圆与矩形的长的交点,若无交点,则一定不能对用最少的圆覆盖矩形有贡献。

    2、如果两个圆与矩形相交所得的线段重合,那这两个圆一定能把矩形在两线段并集的那部分所覆盖。问题转化为用圆与矩形相交所得的线段覆盖矩形的长。

    3、按线段左端点排序,对于某个已选择的线段a,求它后面满足b.L <= a.R的线段b的b.R的最大值,依次类推。

    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<cmath>
    #include<iostream>
    #include<sstream>
    #include<iterator>
    #include<algorithm>
    #include<string>
    #include<vector>
    #include<set>
    #include<map>
    #include<stack>
    #include<deque>
    #include<queue>
    #include<list>
    #define lowbit(x) (x & (-x))
    const double eps = 1e-8;
    inline int dcmp(double a, double b){
        if(fabs(a - b) < eps) return 0;
        return a > b ? 1 : -1;
    }
    typedef long long LL;
    typedef unsigned long long ULL;
    const int INT_INF = 0x3f3f3f3f;
    const int INT_M_INF = 0x7f7f7f7f;
    const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
    const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
    const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
    const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
    const int MOD = 1e9 + 7;
    const double pi = acos(-1.0);
    const int MAXN = 10000 + 10;
    const int MAXT = 10000 + 10;
    using namespace std;
    struct Node{
        double pos, r;
        double L, R;
        bool operator < (const Node& rhs)const{
            return L < rhs.L;
        }
    }num[MAXN];
    
    int main(){
        int n;
        double l, w;
        while(scanf("%d%lf%lf", &n, &l, &w) == 3){
            double pos, r;
            int cnt = 0;
            for(int i = 0; i < n; ++i){
                scanf("%lf%lf", &pos, &r);
                double tmpl = r * r - w * w / 4.0;
                if(dcmp(tmpl, 0.0) <= 0) continue;
                ++cnt;
                num[cnt].pos = pos;
                num[cnt].r = r;
                num[cnt].L = pos - sqrt(tmpl);
                num[cnt].R = pos + sqrt(tmpl);
            }
            sort(num + 1, num + cnt + 1);
            int ans = 0;
            double st = 0.0;
            bool ok = false;
            for(int i = 1; i <= cnt; ++i){
                if(dcmp(st, l) >= 0){
                    ok = true;
                    break;
                }
                ++ans;
                if(num[i].L > st){
                    ok = false;
                    break;
                }
                double ma = -1.0;
                int j;
                for(j = i; j <= cnt; ++j){
                    if(dcmp(num[j].L, st) <= 0){
                        ma = max(ma, num[j].R);
                    }
                    else break;
                }
                st = ma;
                i = j - 1;
            }
            if(dcmp(st, l) >= 0){
                ok = true;
            }
            if(ok){
                printf("%d
    ", ans);
            }
            else{
                printf("-1
    ");
            }
        }
        return 0;
    }
    

      

  • 相关阅读:
    HarmonyOS (鸿蒙操作系统)你值得拥有
    远端FTP文件与本地文件如何进行Diff
    多线程下载一个大文件的速度更快的真正原因是什么?
    一道有意思的面试题
    BootstrapVue 安装指南
    bash shell数组使用总结
    APP测试之ADB最全指南
    APP测试用例整理
    直播类音视频测试整理
    IOS手机耗电量测试
  • 原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/7417761.html
Copyright © 2011-2022 走看看