博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj1328——Radar Installation(贪心)
阅读量:2345 次
发布时间:2019-05-10

本文共 2108 字,大约阅读时间需要 7 分钟。

Description

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.

这里写图片描述
Figure A Sample Input of Radar Installations

Input

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

Output

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.

Sample Input

3 2

1 2
-3 1
2 1

1 2

0 2

0 0

Sample Output

Case 1: 2

Case 2: 1

#include 
#include
#include
#include
#include
//#include
#include
#include
#include
#include
#include
#define MAXN 1010#define mod 2012#define INF 0x3f3f3f3fusing namespace std;struct Node{ double left,right;};Node p[MAXN];bool cmp(Node a,Node b){ return a.left
>n>>d&&(n||d)) { bool flag=false; for(int i=0; i
>x>>y; p[i].left=x-sqrt(d*d-y*y); p[i].right=x+sqrt(d*d-y*y); if(fabs(y)>d) flag=true; } cout << "Case " << cnt++ << ": "; if(flag) cout<<"-1"<
tmp.right) { ans++; tmp=p[i]; } else if(p[i].right

转载地址:http://rncvb.baihongyu.com/

你可能感兴趣的文章
在C++面向对象编程语言中,以下关于接口的阐述不正确的是:----腾讯2016研发工程师笔试题(一)
查看>>
下面关于HTTP协议的说法正确的是:----腾讯2016研发工程师笔试题(一)
查看>>
关于多线程和多进程编程,下面描述正确的是():----腾讯2016研发工程师笔试题(一)
查看>>
动态规划--钢条切割
查看>>
有多少个进程被 fork 出来了?----阿里巴巴2015校招研发在线笔试题
查看>>
下面的函数哪个是系统调用而不是库函数()?----阿里巴巴2015校招研发在线笔试题
查看>>
下列不属于hash碰撞解决方法的是()。----阿里巴巴2015校招研发在线笔试题
查看>>
针对外部存储器(如磁盘)上存放的程序和数据,说法正确的是()。----阿里巴巴2015校招研发在线笔试题
查看>>
下列关于线程调度的叙述中,错误的是()。----阿里巴巴2015校招研发在线
查看>>
如何扩展 web 服务器?----阿里巴巴2015校招研发在线
查看>>
有两个32bit的数A、B,使用下面方式得到32bit的数C、D。哪一种可以使用C、D得到A、B的值?----阿里巴巴2015校招研发在线
查看>>
如何设计数据表、解决数据库并发访问瓶颈、数据库事务----阿里巴巴2015校招研发在线
查看>>
皮划艇找瓶子--------阿里巴巴2015校招研发在线
查看>>
HTTP的会话有四个过程,请选出不是的一个()----百度2016研发工程师笔试题(六)
查看>>
在ISO/OSI参考模型中,网络层的主要功能是()----百度2016研发工程师笔试题(六)
查看>>
MapReduce框架中,在Map和Reduce之间的combiner的作用是()----百度2016研发工程师笔试题(六)
查看>>
计算页号----百度2016研发工程师笔试题(六)
查看>>
在一个分时操作系统中,进程出现由运行状态进入就绪状态,由阻塞状态进入就绪状态的原因分别可能是()
查看>>
数据库 alter 语句的使用----百度2016研发工程师笔试题(六)
查看>>
数据库恢复的基础是利用转储的冗余数据。这些转储的冗余数据包括()----百度2016研发工程师笔试题(六)
查看>>