POJ 1328 Radar Installation

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ 1328 Radar Installation相关的知识,希望对你有一定的参考价值。

题意:给定n个坐标(均在x轴上方),已知雷达的辐射半径为 d.

  在x轴上建造雷达,输出最小建造雷达的数目.

  

  node[i].l = x - sqrt(d*d-y*y);
  node[i].r = x + sqrt(d*d-y*y);

  

思路:化平面为区间

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cstring>
 4 
 5 #include<string> 
 6 #include<vector>
 7 #include<set>
 8 #include<map>
 9 #include<math.h>
10 
11 #include<algorithm>
12 #include<iostream>
13 
14 const int INF = 0x7f7f7f7f;
15 using namespace std;
16 typedef long long ll;
17 
18 struct Node{
19     double l,r;
20 };
21 Node node[1010];
22 bool vis[1010];
23 bool cmp(Node a,Node b){
24     return a.r < b.r;
25 }
26 
27 int main(){
28     
29     int n,kase = 1;
30     double d;
31     while(scanf("%d%lf",&n,&d) != EOF && (n!=0)){
32         bool f = true; //看是否有小岛无法被覆盖 
33         for(int i = 0 ; i < n ; i ++){
34             double x,y;
35             scanf("%lf%lf",&x,&y);
36             node[i].l = x - sqrt(d*d-y*y);
37             node[i].r = x + sqrt(d*d-y*y);
38             if(y > d) f = false;
39         }
40         if(!f){
41             printf("Case %d: -1\n",kase++);
42         }else{
43             memset(vis,0,sizeof(vis));
44             sort(node,node+n,cmp);
45             int cnt = 0;
46             double pos;
47             for(int i = 0 ; i < n ; i ++){
48                 if(vis[i])    continue;
49                 pos = node[i].r;
50                 cnt++;
51                 for(int j = i + 1; j < n ; j ++){
52                     if(node[j].l <= pos) vis[j] = true;
53                     else break;
54                 }                        
55             }
56             printf("Case %d: %d\n",kase++,cnt);
57         }
58         
59         /*
60          double temp=interval[0].r;
61         for(int i=1;i<n;i++)
62         {
63           if(temp<interval[i].l)
64           {
65             cnt++;
66             temp=interval[i].r;
67           }
68         }
69         
70         */            
71     }
72     return 0;
73 } 

 

以上是关于POJ 1328 Radar Installation的主要内容,如果未能解决你的问题,请参考以下文章

poj 1328 Radar Installation

poj1328 Radar Installation

POJ1328 Radar Installation

[POJ1328] Radar Installation

Radar Installation POJ - 1328

poj1328Radar Installation