文档章节

poj 1328 Radar Installation

locusxt
 locusxt
发布于 2013/12/03 10:19
字数 637
阅读 63
收藏 0
poj

Radar Installation
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]


/*=============================================================================
#     FileName: radar.cpp
#         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;
}



© 著作权归作者所有

上一篇: poj 1035 Spell checker
下一篇: poj 3714 raid
locusxt
粉丝 27
博文 140
码字总数 90989
作品 0
海淀
程序员
私信 提问
POJ 1328: Radar Installation

题目在此 解题思路: 以岛屿坐标为圆心,输入值为半径画圆,此圆会与 X 轴相交于 S、E 两点(岛屿 Y 坐标等于圆半径时,交一点;Y 坐标大于圆半径的情况提前排除,不参与后面的计算)。然后对...

Alexander_zhou
2014/02/22
185
0
一个搞ACM需要掌握的算法

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

long0404
2015/06/24
0
0
算法进阶路径

第一阶段:练经典常用算法,下面的每个算法给我打上十到二十遍,同时自己精简代码, 因为太常用,所以要练到写时不用想,10-15分钟内打完,甚至关掉显示器都可以把程序打 出来. 1.最短路(Fl...

暖冰
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
[BZOJ1328]Radar Installation(贪心)

传送门 题意:有n个海岛,分别分布在坐标系上,在x轴上放雷达,使得雷达可以覆盖到所有的海岛,雷达的辐射范围是一个圆有一个固定的辐射半径R,问最少需要打多少个雷达可以覆盖所有的海岛 对...

cabi_zgx
2018/04/20
0
0

没有更多内容

加载失败,请刷新页面

加载更多

【0918】正则介绍_grep

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

飞翔的竹蜻蜓
33分钟前
4
0
为什么要在网站中应用CDN加速?

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

云漫网络Ruan
今天
8
0
亚玛芬体育(Amer Sports)和信必优正式启动合作开发Movesense创新

亚玛芬体育和信必优正式启动合作开发Movesense创新,作为亚玛芬体育的完美技术搭档,信必优利用Movesense传感器技术为第三方开发移动应用和服务。 Movesense基于传感器技术和开放的API,测量...

symbiochina88
今天
4
0
创龙TI AM437x ARM Cortex-A9 + Xilinx Spartan-6 FPGA核心板规格书

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

Tronlong创龙
今天
5
0
好程序员Java学习路线分享MyBatis之线程优化

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

好程序员官方
今天
6
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部