关闭

ACM POJ 1328 Radar Installation

标签: acmpoj
231人阅读 评论(0) 收藏 举报
分类:
Time Limit:2000MS    Memory Limit:65536KB    64bit IO Format:%lld & %llu

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.

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



题目大意: x轴上方是海,下面是陆地,海面上给出若干个小岛,现在给出灯塔可见半径d和每个灯塔的坐标,要求在陆地上选择建最少的灯塔保证每个岛都能可见,无解输出-1;


分析:首先如果无解,那么一定存在某个灯塔的坐标y大于灯塔半径k,直接输出-1;

如果有解,那么每个灯塔在海岸线上一定存在一个灯塔的可建范围l,r;

此时我们只需要从这些区间当中找到最少灯塔即可。


那么问题来了,如何找呢?

|

|

|

贪心!


我们将每个小岛按照右范围r从小到大排好,从最左边的岛开始,只要接下来的岛的左范围l小于当前岛的r,那么这两个岛一定可以共用一个灯塔,一直到范围r外的小岛,那么此时肯定需要建立其他灯塔才能满足解。


代码如下:


<script src="https://code.csdn.net/snippets/741681.js"></script>




0
0
查看评论

POJ 1328 Radar Installation-放置雷达(贪心,区间,二维转一维)

http://poj.org/problem?id=1328 这个题题意是说,海上有n多岛,在海岸线上(x轴)建一个雷达能覆盖到与它距离不超过d的岛,求覆盖所有岛的最小雷达数。 . . . . . . . . . 本题贪心思路是把点转化为在x轴坐标上的区间(即能保证覆盖该小...
  • ACM_10000h
  • ACM_10000h
  • 2014-11-11 11:44
  • 1557

POJ:1328 Radar Installation 思路以及测试数据

Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 76845   Accepted: 1721...
  • DeepMindMan
  • DeepMindMan
  • 2016-08-22 17:16
  • 1778

poj1328Radar Installation(贪心+区间选择)

Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 80210   Accepted: 17922 Descripti...
  • luckcircle
  • luckcircle
  • 2016-12-13 17:00
  • 1136

CSU-ACM2017暑期训练7-模拟&&贪心 A - Radar Installation POJ - 1328

题目: 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...
  • Zhangcan233
  • Zhangcan233
  • 2017-08-02 22:23
  • 101

POJ 1328 Radar Installation

Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43793   Accepted: 9704 Descriptio...
  • u011107911
  • u011107911
  • 2013-08-30 23:30
  • 429

poj 1328 Radar Installation

每个岛都在X轴上有一个区间可以被雷达覆盖,x1为可覆盖的左端点,x2为可覆盖的右端点,x1,x2关于岛的X对称。 先对岛以x排序,然后贪心。 假设当前雷达为nowx,如果当前岛的x1<=nowx,那么更新nowx=min(nowx,x2) 否则加一个新雷达,设置nowx=当前岛的x2 总之就是...
  • u014689045
  • u014689045
  • 2014-07-18 08:37
  • 881

Radar Installation(poj)1328

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 locat...
  • WYwysun
  • WYwysun
  • 2016-09-23 21:54
  • 185

poj 1328 Radar Installation

先看一下题目: 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 poin...
  • tt_twilight
  • tt_twilight
  • 2016-10-09 15:34
  • 95

POJ 1328:Radar Installation

问题描述 海上有n个小岛,想要沿着海岸线部署雷达来覆盖小岛,雷达的辐射范围跟小岛位置已知,求最少可以用几个雷达来覆盖所有岛屿。 解题思路 这是省赛之前做的一道题。贪心。将每个小岛的位置转化为在可以被辐射到时,海岸线上可以安放雷达的起点跟终点位置,然后按照起点有小到大排序,从前向后覆盖每一个还没有被覆...
  • liangyuppp
  • liangyuppp
  • 2017-08-03 10:35
  • 46

poj 1328 Radar Installation

#include #include #include #define MAX_N 1100 using namespace std; pair point[MAX_N]; pair arr[MAX_N]; //input int n,d; //answer int ans; int...
  • u013008291
  • u013008291
  • 2014-06-01 16:04
  • 407
    个人资料
    • 访问:63017次
    • 积分:2202
    • 等级:
    • 排名:千里之外
    • 原创:195篇
    • 转载:7篇
    • 译文:0篇
    • 评论:2条
    队友
    最新评论