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. 【WIP】Swift4 闭包

    创建: 2018/06/05 闭包的声明  闭包的概要 { (参数表) -> 型 in { ... } ● 参数不可以带默认值 ● 参数不可以带标签 ●  定义闭包并直接呼出必须要被代入 {re ...

  2. DOM0、DOM2级事件

    JavaScript DOM0.DOM2级事件 1.DOM0级事件:on+事件类型 在html行内直接绑定,也就是通过行内js绑定的例如<span onclick="alert('1' ...

  3. web框架原理,http 协议

    目录 web框架原理 web框架是什么东西 执行代码用浏览器访问一下 输出结果 http 协议 http 协议简介 http 协议概述 http 工作原理 http请求方法 http 状态码 url介 ...

  4. [题解](树的计数)luogu_P4430猴子打架_/_luogu_P4981父子

    来源:题解 比较不错的博客:http://www.cnblogs.com/dirge/p/5503289.html 最后生成一颗无根树,有n^(n-2)种情况,打架的顺序有(n-1)!种 #inclu ...

  5. [題解](水/并查集)luogu_P2170選學霸

    很簡單的水題,因為智障沒有A所以發篇博客 同樣的題:luogu_P1455 搭配購買 用并查集維護一下所有實力相等的人的size,然而你可以選多個size......,於是跑個背包就行了,只要注意一下 ...

  6. Codeforces 1119D(贡献计算)

    题目传送 排序看一看. 关键点在于发现性质: 算一个点的贡献时: 1.与后一个有重叠.\[当 a[i] + r >= a[i + 1] + l, 即 r - l >= a[i + 1] - ...

  7. UVa12304(计算几何中圆的基本操作)

    断断续续写了250多行的模拟,其间被其他事情打扰,总共花了一天才AC吧~ 这道题目再次让我明白,有些事情看起来很难,实际上并没有我们想象中的那么难.当然了我主要指的不是这个题的难度…… 也是初学计算几 ...

  8. Technocup 2017 - Elimination Round 1 (Unofficially Open for Everyone, Rated for Div. 2) D

    The organizers of a programming contest have decided to present t-shirts to participants. There are ...

  9. 洛谷 P4137 Rmq Problem / mex

    https://www.luogu.org/problemnew/show/P4137 只会log^2的带修主席树.. 看了题解,发现有高妙的一个log做法:权值线段树上,设数i对应的值ma[i]为数 ...

  10. python中的os.path.dirname与os.path.dirname(__file__)的用法

    python中的os.path.dirname的用法 os.path.dirname(path) 语法:os.path.dirname(path) 功能:去掉文件名,返回目录 如: print(os. ...