zoukankan      html  css  js  c++  java
  • 【POJ 1328】 Radar Installation

    【题目链接】

               http://poj.org/problem?id=1328

    【算法】

               每个雷达都位于笛卡尔坐标系的x轴上,因此,对于每个岛屿,我们都可以用勾股定理算出它的有效管辖区域

               那么,问题就被转化成了 : 给定若干个区间,要求每个区间内都要有一个点,最小化点的个数

               我们将这些区间按左端点排序,然后贪心,即可

    【代码】

                

    #include <algorithm>  
    #include <bitset>  
    #include <cctype>  
    #include <cerrno>  
    #include <clocale>  
    #include <cmath>  
    #include <complex>  
    #include <cstdio>  
    #include <cstdlib>  
    #include <cstring>  
    #include <ctime>  
    #include <deque>  
    #include <exception>  
    #include <fstream>  
    #include <functional>  
    #include <limits>  
    #include <list>  
    #include <map>  
    #include <iomanip>  
    #include <ios>  
    #include <iosfwd>  
    #include <iostream>  
    #include <istream>  
    #include <ostream>  
    #include <queue>  
    #include <set>  
    #include <sstream>  
    #include <stdexcept>  
    #include <streambuf>  
    #include <string>  
    #include <utility>  
    #include <vector>  
    #include <cwchar>  
    #include <cwctype>  
    #include <stack>  
    #include <limits.h> 
    using namespace std;
    #define MAXN 1010
    
    int n,d,i,x,y,ans,TC;
    double dis,pos;
    bool flag;
    
    struct info
    {
            double l,r;
    } a[MAXN];
    
    inline bool cmp(info a,info b) 
    {
            return a.l < b.l;
    }
    
    int main() 
    {
        
            while (scanf("%d%d",&n,&d) != EOF && n && d)
            {
                    flag = false;
                    for (i = 1; i <= n; i++)
                    {
                            scanf("%d%d",&x,&y);
                            if (y > d) flag = true;
                            dis = sqrt(d*d-y*y);
                            a[i] = (info){x-dis,x+dis};    
                    }    
                    if (flag) 
                    {
                            printf("Case %d: %d
    ",++TC,-1);
                            continue;
                    }
                    sort(a+1,a+n+1,cmp);
                    ans = 1; pos = a[1].r;
                    for (i = 2; i <= n; i++)
                    {
                            if (a[i].l > pos)
                            {
                                    ans++;
                                    pos = a[i].r;
                            } else pos = min(pos,a[i].r);
                    }
                    printf("Case %d: %d
    ",++TC,ans);
            }
            
            return 0;
        
    }
  • 相关阅读:
    CSS学习笔记
    metadata的深入
    [极客大挑战 2019]BabySQL
    [极客大挑战 2019]LoveSQL
    [强网杯 2019]随便注
    [SUCTF 2019]CheckIn 1
    [ZJCTF 2019]NiZhuanSiWei 1
    [BJDCTF2020]Easy MD5
    [极客大挑战 2019]BuyFlag
    [ACTF2020 新生赛]BackupFile
  • 原文地址:https://www.cnblogs.com/evenbao/p/9238422.html
Copyright © 2011-2022 走看看