ZOJ地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=360

POJ地址:http://poj.org/problem?id=1328

解题思路:贪心

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 #include <math.h>
 5 
 6 struct P{
 7     double x, y, left, right;
 8 }p[];
 9 
 int cmp(const void *a, const void *b){
     struct P *c = (struct P *)a;
     struct P *d = (struct P *)b;
     return c->left > d->left ?  : -;
 }
 
 int main(){
     int n, i, j, r, ans, lose, Case = ;
     double d, x, dis, high;
     while(scanf("%d %d", &n, &r) != EOF){
         if(n ==  && r == ){
             break;
         }
         lose = ;
         d = (double)r;
         for(i = ; i < n; i++){
             scanf("%lf %lf", &p[i].x, &p[i].y);
             if(p[i].y > d){                                     //如果某个点的y左边大于雷达半径,那么一定无法覆盖
                 lose = ;
             }
             dis = sqrt(d * d - p[i].y * p[i].y);
             p[i].left = p[i].x - dis;
             p[i].right = p[i].x + dis;
         }
         if(lose == ){
             printf("Case %d: -1\n", Case++);
             continue;
         }
         qsort(p, n, sizeof(p[]), cmp);
         ans = ;
         high = p[].right;      //令第一个点的右端点为最远点
         for(i = ; i < n; i++){
             if(p[i].left <= high){
                 high = p[i].right < high ? p[i].right : high;//如果该点的左端点在最远点内,更新最远点
             }
             else{               //如果左端点不在最远点内,雷达数+1,更新最远点
                 ans++;
                 high = p[i].right;
             }
         }
         printf("Case %d: %d\n", Case++, ans);
     }
     return ;

53 }

ZOJ-1360 || POJ-1328——Radar Installation的更多相关文章

  1. 贪心 POJ 1328 Radar Installation

    题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...

  2. POJ 1328 Radar Installation 贪心 A

    POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...

  3. poj 1328 Radar Installation (简单的贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42925   Accepted: 94 ...

  4. poj 1328 Radar Installation(nyoj 287 Radar):贪心

    点击打开链接 Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43490   Accep ...

  5. poj 1328 Radar Installation【贪心区间选点】

    Radar Installation Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) ...

  6. poj 1328 Radar Installation(贪心)

    Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...

  7. POJ 1328 Radar Installation【贪心】

    POJ 1328 题意: 将一条海岸线看成X轴,X轴上面是大海,海上有若干岛屿,给出雷达的覆盖半径和岛屿的位置,要求在海岸线上建雷达,在雷达能够覆盖全部岛屿情况下,求雷达的最少使用量. 分析: 贪心法 ...

  8. poj 1328 Radar Installation(贪心+快排)

    Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...

  9. poj 1328 Radar Installation 排序贪心

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 56702   Accepted: 12 ...

  10. POJ 1328 Radar Installation(很新颖的贪心,区间贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 106491   Accepted: 2 ...

随机推荐

  1. input输入框修改后自动跳到最后一个字符

    <input class="m-form-control" onpaste="return false" placeholder="直播间名称& ...

  2. Unity3D研究院之IOS&Android收集Log文件(六十二)

    开发项目的时候尤其在处理与服务器交互这块,如果服务端程序看不到客户端请求的Log信息,那么无法修改BUG.在Windows上Unity会自动讲Log文件写入本地,但是在IOS和Android上确没有这 ...

  3. web前端篇:JavaScript正则表达式

    目录 JavaScript正则表达式 1.创建正则表达式 1.1方法1:直接量语法 1.2 方法2:创建RegExp对象的语法 1.3 区别: 1.4正则表达式使用 2.正则对象的属性 2.1.属性 ...

  4. android webview 视频相关

    //设置为false则可以自动播放页面音视频 页面必须设置autoplay或者调用document.getElementById("video").play(); $(" ...

  5. SpringBoot | 集成Redis

    Windows下安装: https://github.com/MicrosoftArchive/redis/releases zip下就解包到自定义目录下,msi就跟着步骤安装 进入安装目录下运行命令 ...

  6. JS创建函数的方法

    方法一:函数声明. function foo(){ } 方法二:函数表达式. var foo=function(){ } 另外还有一种自执行函数表达式.主要用于创建一个新的作用域,在此作用域内声明的变 ...

  7. POJ-1258-Agri Ned

    链接:https://vjudge.net/problem/POJ-1258#author=fuxianda 题意: 有n个农场,已知这n个农场都互相相通,有一定的距离,现在每个农场需要装光纤,问怎么 ...

  8. Jasper_crosstab_measure_display a value of field in crosstab total row

    1.create a measure <measure name="myField" class="java.lang.String"> <m ...

  9. disasters

    1.list all the natural disasters to the best of your knowledge. 2.What are the possible causes for s ...

  10. debian使用apt安装时出现“更换介质,插入驱动器"/media/chrom/"再按回车键”的提示,无法从网络安装,解决?

    原文链接:https://www.zhihu.com/question/22132663 nano /etc/apt/sources.list把那出现的那行注释掉:含CD盘的一行:然后apt-get ...