博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1328 Radar Installation(贪心)
阅读量:6186 次
发布时间:2019-06-21

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

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 21 2-3 12 11 20 20 0

Sample Output

Case 1: 2

Case 2: 1

首先考虑把坐标维度降下来再考虑贪心算法

#include
#include
#include
#include
#include
#include
typedef long long LL;using namespace std;double d,x,y;struct node{ double l,r;}e[1010];int cmp(node l1,node l2){ return l1.r
pos) { ans++; pos=e[i].r; } if(e[i].r

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

你可能感兴趣的文章
gulp API 简介
查看>>
项目经理的权宜之计
查看>>
redis应用之使用sentinel实现主从复制高可用
查看>>
软件工程院校排名
查看>>
Excle 创建下拉列表
查看>>
SSH原理之图文详解
查看>>
yum的repo文件详解、以及epel简介、yum源的更换
查看>>
我的友情链接
查看>>
第 三 十 九 天:更 换 yum 源 和 卸 载 图 形 界 面
查看>>
1,Python13_day1
查看>>
flask-uploads扩展的使用
查看>>
小猪佩奇社会人专用服务器,有意思的python小程序,附python代码
查看>>
设计模式--代理模式
查看>>
codeblock 快捷键
查看>>
共享程序集和强命名程序集
查看>>
机器学习--逻辑回归_LR(内附细说极大似然估计,梯度下降法)
查看>>
Centos7禁止或者允许开机启动服务
查看>>
浏览器重绘和回流
查看>>
14-python-函数
查看>>
微信小程序开发之路之组件化
查看>>