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. POJ2406【KMP-next数组】

    关于next的解释原文:点点点 //#include <bits/stdc++.h> #include<cstdio> #include<string.h> #in ...

  2. OPENGL1_环境

    补充说明: 1 vs2010自带opengl的库,不需要单独下载或做任何配置,(但是lib文件,dll文件放的位置过于分散,用的时候感觉不好用) 使用时直接用 #include <gl/GL.h ...

  3. bzoj 2597: [Wc2007]剪刀石头布【最小费用最大流】

    脑子不太清楚一个zz问题调了好久-- 首先正难则反,因为三元环好像没什么特点,就考虑让非三元环个数最小 考虑非三元环特点,就是环上一定有一个点的入度为2,联系整张图,三元环个数就是每个点C(入度,2) ...

  4. nutzboot dubbo zookeeper简单使用

    提供方和消费方properties 配置基本差不多 nutz.application.name这个值不一样 提供方配置自动端口就行server.port=0 消费方一般需要对外提供web服务配置ip和 ...

  5. jmeter常用的beanshell脚本

    时间戳下载文件保存响应内容断言连接数据库解析jsonlist递归创建多级目录 常用内置变量调用cmd文件GUI小命令 时间戳import java.text.SimpleDateFormat;impo ...

  6. 调试PHP

    echo "<br/>"; print_r($array);

  7. vue.js2.0实战填坑记录

    访https://github.com/bailicangdu/vue2-elm的PC商城 在创建的 router 对象中,如果不配置 mode,就会使用默认的 hash 模式,该模式下会将路径格式化 ...

  8. Spring-打印机案例

    1.导包 <!--beans--><dependency> <groupId>org.springframework</groupId> <art ...

  9. SVN中如何去除版本控制器

    SVN,大家都熟悉,做项目都知道,不知道你有没有遇到每次提交的代码的时候,都会把bin和obj自动生成的文件夹提交SVN服务器上 其实这里都不需要提交,每次生成都提交,可能还会容易冲突,如何不让bin ...

  10. 開玩樹莓派(一):安裝Raspbian系統

    目錄: 開玩樹莓派(一):安裝Raspbian系統 開玩樹莓派(二):配置IP,實現無顯示器局域網內Putty連接和RDP遠程 開玩樹莓派(三):Python編程 開玩樹莓派(四):GPIO控制和遠程 ...