## poj 1328 Radar Installation 原

locusxt

 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 45575 Accepted: 10157

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``````

Source

[Submit]   [Go Back]   [Status]   [Discuss]

``````/*=============================================================================
#         Desc:
#       Author: zhuting
#        Email: cnjs.zhuting@gmail.com
#     HomePage: my.oschina.net/locusxt
#      Version: 0.0.1
#    CreatTime: 2013-12-03 00:12:22
#   LastChange: 2013-12-03 10:20:49
#      History:
=============================================================================*/
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#define maxn 1005
using namespace std;

struct line/*区间结构*/
{
double left;/*左右边界*/
double right;
};
struct line li[maxn];

bool cmp (struct line a, struct line b)/*sort的比较函数*/
{
if(a.left == b.left) return b.right < a.right;
return a.left < b.left;
}

int main()
{
int i;
int case_num;
int n;
double d;/*尽量都用double,避免错误*/
double x, y;
double tmp, l, r;

double pos;
int num;
bool is_possible;/*是否有解*/

case_num = 0;
while(1)
{
++case_num;
scanf("%d%lf", &n, &d);
if (!n && !d) break;
is_possible = 1;
if (d <= 0) is_possible = 0;/*半径得大于0*/
for (i = 0; i < n; ++i)
{
scanf("%lf%lf", &x, &y);
if (!is_possible) continue;
tmp = (d*d - y*y);/*一定大于0*/
if (tmp < 0 || y < 0)
{
is_possible = 0;
continue;
}
tmp = sqrt(tmp);
l = x - tmp;
r = x + tmp;
li[i].left = l;
li[i].right = r;
}
if (!is_possible)
{
printf("Case %d: -1\n", case_num);
continue;
}

sort(li, li + n, cmp);

pos = li[0].right;/*一开始,第一个雷达位置为区间0的右边界*/
num = 1;
for (i = 1; i < n; ++i)
{
if (li[i].left > pos)/*区间左边界在当前雷达的右边,则一定得加一个雷达*/
{
++num;
pos = li[i].right;/*新雷达在区间最右*/
}
else if (li[i].right < pos)/*区间右边界在当前雷达左侧,则新雷达移动至现区间右边界*/
pos = li[i].right;
}
printf("Case %d: %d\n", case_num, num);
}
return 0;
}``````

### locusxt

Alexander_zhou
2014/02/22
185
0

ACM的竞赛性强,因此自己应该和自己的实际应用联系起来.适合自己的才是好的,有的人不适合搞算法,喜欢系统架构,因此不要看到别人什么就眼红,发挥自己的长处,这才是重要的. 第一阶段：练经典常用...

long0404
2015/06/24
0
0

2016/04/02
156
1
eclipse用spring mvc框架搭配tomcat开发web项目，启动tomcat报错，错误信息如下，有没有大神帮忙看一下

at java.util.zip.ZipFile\$ZipFileInputStream.read(Unknown Source) at java.util.zip.ZipFile\$ZipFileInflaterInputStream.fill(Unknown Source) at java.util.zip.InflaterInputStream.re......

2017/01/14
594
6

cabi_zgx
2018/04/20
0
0

【0918】正则介绍_grep

【0918】正则介绍_grep 9.1 正则介绍_grep上 9.2 grep中 9.3 grep下 一、正则介绍 正则是一串有规律的字符串，它使用单个字符串来描述或匹配一系列符合某个语法规则的字符串。 二、grep工具 ...

33分钟前
4
0

1. 网页加载速度更快 在网站中使用CDN技术最直接的一个好处就是它可以加快网页的加载速度。首先，CDN加速的内容分发是基于服务器缓存的，由于CDN中缓存了不少数据，它能够给用户提供更快的页...

8
0

symbiochina88

4
0

SOM-TL437xF是一款广州创龙基于TI AM437x ARM Cortex-A9 + Xilinx Spartan-6 FPGA芯片设计的核心板，采用沉金无铅工艺的10层板设计，适用于高速数据采集和处理系统、汽车导航、工业自动化等领...

Tronlong创龙

5
0

好程序员Java学习路线分享MyBatis之线程优化，我们的项目存在大量用户同时访问的情况，那么就会出现大量线程并发访问数据库，这样会带来线程同步问题，本章我们将讨论MyBatis的线程同步问...

6
0