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. 51nod - 1188 - 最大公约数之和 V2 - 数论

    https://www.51nod.com/Challenge/Problem.html#!#problemId=1188 求\(\sum\limits_{i=1}^{n-1}\sum\limits_ ...

  2. Codevs 1141 数列

    1141 数列 题目描述 Description 给定一个正整数k(3≤k≤15),把所有k的方幂及所有有限个互不相等的k的方幂之和构成一个递增的序列,例如,当k=3时,这个序列是: 1,3,4,9, ...

  3. Tcl/Tk语言学习------拆分字符串

    字符串的拆分 前言 字符串的处理是每种语言经常会遇到的问题,tcl作为一门脚本语言自然也不例外,关于字符串的拆分,一般会有两种情况:1.使用单个字符拆分,2.使用字符串拆分. 1.使用单个字符拆分字符 ...

  4. 利用多项式实现图像几何校正(Matlab实现)

    1.原理简述:     根据两幅图像中的一些已知对应点(控制点对),建立函数关系式,通过坐标变换,实现失真图像的几何校正. 设两幅图像坐标系统之间畸变关系能用解析式来描述: 根据上述的函数关系,可以依 ...

  5. E. XOR and Favorite Number (莫队板子题)

    题目链接 #include <bits/stdc++.h> using namespace std; typedef long long ll; inline int read() { , ...

  6. 牛客寒假6-D.美食

    链接:https://ac.nowcoder.com/acm/contest/332/D 题意: 小B喜欢美食. 现在有n个美食排成一排摆在小B的面前,依次编号为1..n,编号为i的食物大小为 a[i ...

  7. Influxdb 时序数据库 windows 安装

    Influxdb 是一款比较火爆的时序数据库,本文介绍如何在 windows 平台下安装. 1.场景: windows 平台的 influxdb 似乎只支持单机非windows 服务的安装方式 适用于 ...

  8. Rasheda And The Zeriba Gym - 100283A  计算几何

    http://codeforces.com/gym/100283/problem/A 考虑到多边形是不稳定的,是可以变来变去的. 那么总是可以把每个点放到圆上. 所以只需要判断圆心角是不是小于等于36 ...

  9. simhash与重复信息识别

    在工作学习中,我往往感叹数学奇迹般的解决一些貌似不可能完成的任务,并且十分希望将这种喜悦分享给大家,就好比说:“老婆,出来看上帝”…… 随着信息爆炸时代的来临,互联网上充斥着着大量的近重复信息,有效地 ...

  10. hdu2475Box(splay树形转线性)

    链接 推荐一篇帖子 http://blog.csdn.net/lyhypacm/article/details/6734748 这题暴力不可行主要是因为这颗树可能极度不平衡,不能用并查集是不能路径压缩 ...