Radar

时间限制:1000 ms  |  内存限制:65535 KB
难度:3
描述
Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d distance, so an island in the sea can be covered by a radius installation, if the distance between them is at most d.

We use Cartesian coordinate system, defining the coasting is the x-axis. The sea side is above x-axis, and the land side below. Given the position of each island in the sea, and given the distance of the coverage of the radar installation, your task is to write a program to find the minimal number of radar installations to cover all the islands. Note that the position of an island is represented by its x-y coordinates.

输入
The input consists of several test cases. The first line of each case contains two integers n (1<=n<=1000) and d, where n is the number of islands in the sea and d is the distance of coverage of the radar installation. This is followed by n lines each containing two integers representing the coordinate of the position of each island. Then a blank line follows to separate the cases.

The input is terminated by a line containing pair of zeros

输出
For each test case output one line consisting of the test case number followed by the minimal number of radar installations needed. "-1" installation means no solution for that case.
样例输入
3 2
1 2
-3 1
2 11 2
0 20 0
样例输出
Case 1: 2
Case 2: 1
#include<stdio.h>
#include<math.h>
#include<stdlib.h>#define MAX 1005int num = 1;struct land
{double l;double r;
}land_1[MAX];int cmp(const void *a, const void *b)                          //  在c中运用qsort函数进行排序所需的自己的cmp函数标准模式
{return (*(struct land *) a). r > (*(struct land *) b). r ? 1 : -1;              //从小到大进行排序
}int main()
{int count, r, x, y, flag, num_1, i;double now, result;while(scanf("%d%d", &count, &r) && count && r){flag = 1;for(i = 0; i < count; i++){scanf("%d%d", &x, &y);if(!flag)continue;if(y <= r){result =sqrt((double) (r * r -  y * y));land_1[i].l = (double)x - result;land_1[i].r = (double)x + result;//            flag = 1;}elseflag = 0;if(!flag){printf("Case %d: -1\n", num++);continue;}    }qsort(land_1, count, sizeof(land_1[0]), cmp);              //qsort函数的用法num_1 = 1;now = land_1[0].r;for(i = 1; i < count; i++){if(land_1[i].l <= now + 0.00005)continue;now = land_1[i]. r;num_1++;}printf("Case %d: %d\n", num++, num_1);}return 0;
}

radar(nyoj287贪心)相关推荐

  1. POJ - 1328 Radar Installation(贪心+思维)

    题目链接:点击查看 题目大意:校长想通过监控设备覆盖学校内的N座建筑物,每座建筑物被视作一个质点,在笛卡尔坐标系中给出他们的坐标(x,y),并且所有建筑物均处在x轴的上方.因为学校的供电和传输线路均沿 ...

  2. POJ-1328 Radar Installation 贪心

    以每个点算出左右覆盖的雷达所在x轴范围,然后贪心计算出所需圆的个数. 当后一个点的圆心在x轴的左坐标在前一个点的右坐标的右坐标之前,则这个点就会被覆盖. 代码如下:(C++能过,G++ runtime ...

  3. 《算法竞赛进阶指南》刷题记录

    总算闲下来一些辣!然后最近发现其实看书是真真很有效但是一直没有落实!所以决定落实一下这段时间把这本书看完题目做完! 然后发现还有挺多题目挺巧妙的于是一堆博客预警,,,可能最近会写很多比较水(但是我还是 ...

  4. POJ 超详细分类

    POJ 各题算法 1000    A+B Problem            送分题     49%    2005-5-7 1001    Exponentiation         高精度   ...

  5. 【POJ - 1328】Radar Installation(贪心+计算几何)安装雷达辐射岛屿

    题干: Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the ot ...

  6. POJ Radar Installation 1328(雷达)贪心算法

    问题描述 问题链接 Description Assume the coasting is an infinite straight line. Land is in one side of coast ...

  7. NYOJ 287 Radar 贪心之 区间选点

    Radar 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 Assume the coasting is an infinite straight line. Land ...

  8. 【贪心】Radar Installation(poj 1328)

    Radar Installation poj 1328 题目大意: 在平面直角坐标系的一二象限上有n个小岛,现在让你在x坐标上布置雷达,每个雷达可以侦测以它为原心,半径为m的圆内的所有小岛,现在问侦测 ...

  9. 【POJ1328】Radar Installation(贪心,决策包容)

    problem 平面直角坐标系上有n个点. 在x轴上找尽量少的点,并以这些点为圆心画一个半径为d的圆,使得给定的点都在画出来的圆里. 求最少要画的点数,如果不能输出-1. solution 一.不能的 ...

最新文章

  1. 宁德时代机器人编程开发_全球首例丨可编程的活体机器人已诞生,100%青蛙基因,超级计算机时代,将无所不能?!...
  2. CentOS 6和CentOS 7管理系统服务的区别
  3. 分享Kali Linux 2016.2最新镜像20160919
  4. LeetCode Maximal Rectangle(dp)
  5. C# WinForm ProgressBar垂直显示进度和从右向左显示进度
  6. C语言程序设计上机前三题,C语言程序设计(含上机实验与习题解答)
  7. Java selenium 读取网页
  8. Lintcode---二叉树的最大深度
  9. Java Web GenericServlet
  10. 网络安全实验4 SQL注入攻击
  11. GRE词汇会难记到什么程度
  12. 各种时间指标的Power BI度量值,一次全分享给你
  13. Subspace Adversarial Training
  14. arduino小火车交通灯
  15. 华为云 云耀云服务器初体验
  16. 专访架构师周爱民:谈企业软件架构设计 1
  17. 8000字解读全域用户体验丨星巴克的尖刀与钝点
  18. 浙大版《C语言程序设计(第3版)》题目集习题5-6 使用函数输出水仙花数 (20 分) 水仙花数是指一个N位正整数(N≥3),它的每个位上的数字的N次幂之和等于它本身。例如:153=1 ​3 ​​ +
  19. 三国杀online网页版服务器更新,2019年《三国杀Online》更迭汇总,一切为了“fun”...
  20. 9图工具 android,在线自动生成.9png图的Android设计切图工具推荐

热门文章

  1. Windows连接Linux的常用工具
  2. 幸福的源泉:Life is about choices 幸福可以选择
  3. 书评 – 程序员经典读物(2)
  4. python静态属性@property、类方法@classmethod、静态方法@staticmethod和普通方法
  5. 如何成为优秀的科学家
  6. uva 820 Internet Bandwidth
  7. python实现括号分组
  8. DevExpress学习笔记之如何获取Repository Item的值
  9. Google的银河英雄传说
  10. 【线程】——线程的启动和中断