[POJ1328]Radar Installation

试题描述

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

输入

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

输出

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.

输入示例


- 

输出示例

Case :
Case :

数据规模及约定

见“输入

题解

每个点被观测到的条件是它与任意一个岸上的观测站的距离不超过 d,所以以每个点为圆心,d 为半径画圆,与 x 轴交于两点,这两点构成的一条线段即观测站放在这条线段中就能满足这个点。于是转化成了区间选点问题,经典的贪心问题。

注意考虑无解的情况。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <cmath>
using namespace std; int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} #define maxn 1010
struct Line {
double l, r;
Line() {}
Line(double _, double __): l(_), r(__) {}
bool operator < (const Line& t) const { return r < t.r; }
} ls[maxn]; const double eps = 1e-6; int main() {
int n, d, kase = 0;
while(scanf("%d%d", &n, &d) == 2) {
if(!n && !d) break;
bool ok = 1;
for(int i = 1; i <= n; i++) {
int x = read(), y = read();
if(y < 0 || y > d) ok = 0;
double l = sqrt((double)d * d - y * y);
ls[i] = Line((double)x - l, (double)x + l);
}
sort(ls + 1, ls + n + 1);
double last = -1e9;
int ans = 0;
for(int i = 1; i <= n; i++)
if(ls[i].l > last) ans++, last = ls[i].r;
if(!ok) ans = -1;
printf("Case %d: %d\n", ++kase, ans);
} return 0;
}

[POJ1328]Radar Installation的更多相关文章

  1. POJ1328——Radar Installation

    Radar Installation Description Assume the coasting is an infinite straight line. Land is in one side ...

  2. POJ--1328 Radar Installation(贪心 排序)

    题目:Radar Installation 对于x轴上方的每个建筑 可以计算出x轴上一段区间可以包含这个点 所以就转化成 有多少个区间可以涵盖这所有的点 排序之后贪心一下就ok 用cin 好像一直t看 ...

  3. POJ1328 Radar Installation 【贪心&#183;区间选点】

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 54593   Accepted: 12 ...

  4. POJ1328 Radar Installation 解题报告

    Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...

  5. poj1328 Radar Installation(贪心 策略要选好)

    https://vjudge.net/problem/POJ-1328 贪心策略选错了恐怕就完了吧.. 一开始单纯地把island排序,然后想从左到右不断更新,其实这是错的...因为空中是个圆弧. 后 ...

  6. POJ1328 Radar Installation(贪心)

    题目链接. 题意: 给定一坐标系,要求将所有 x轴 上面的所有点,用圆心在 x轴, 半径为 d 的圆盖住.求最少使用圆的数量. 分析: 贪心. 首先把所有点 x 坐标排序, 对于每一个点,求出能够满足 ...

  7. zoj1360/poj1328 Radar Installation(贪心)

    对每个岛屿,能覆盖它的雷达位于线段[x-sqrt(d*d-y*y),x+sqrt(d*d+y*y)],那么把每个岛屿对应的线段求出来后,其实就转化成了经典的贪心法案例:区间选点问题.数轴上有n个闭区间 ...

  8. poj1328 Radar Installation —— 贪心

    题目链接:http://poj.org/problem?id=1328 题解:区间选点类的题目,求用最少的点以使得每个范围都有点存在.以每个点为圆心,r0为半径,作圆.在x轴上的弦即为雷达可放置的范围 ...

  9. ZOJ-1360 || POJ-1328——Radar Installation

    ZOJ地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=360 POJ地址:http://poj.org/problem?id ...

随机推荐

  1. uC/OS-II实现TEST.MAK块

    ################################################################################                     ...

  2. nginx https性能优化

    影响HTTPS速度的主要原因:秘钥交换算法 常见的密钥交换算法有 RSA,ECDHE,DH,DHE 等算法.它们的特性如下: RSA:算法实现简单,诞生于 1977 年,历史悠久,经过了长时间的破解测 ...

  3. centos 安装atop& htop工具

    首先安装rpmforge   Install RPM for CentOS 5.x 32-BIT wget http://pkgs.repoforge.org/rpmforge-release/rpm ...

  4. Java数据结构——双向链表

    //================================================= // File Name : DoublyLinked_demo //------------- ...

  5. php基础语句2

    计算一个月有多少天 $count = date("t",strtotime("2014-09-01")); // 一个月有多少天

  6. lamp环境搭建(ubuntu)

    系统:Ubuntu14.04 方法一.最简单的在线安装 (参考网址:http://os.51cto.com/art/201307/405333.htm) 具体过程: [1]打开终端,执行命令 # su ...

  7. Multiple actions were found that match the request Web API

    在WebAPI工程入口不对外公开的接口不能使用public. [HttpPost] public string PostRequest([FromBody] Model model) { /// } ...

  8. Win7系统中提示:本地无法启动MySQL服务,报的错误:1067,进程意外终止的解决方法。

    Win7系统中提示:本地无法启动MySQL服务,报的错误:1067,进程意外终止的解决方法. 在本地计算机无法启动MYSQL服务错误1067进程意外终止.这种情况一般是my.ini文件配置出错了1.首 ...

  9. (转载)ecshop制作成手机网站的方法

    ecshop用手机访问的时候,会自动跳转到  /mobile 目录下,ecshop自带的wap模板是用wml制作的,如果按这种情况,又需要制作一套模板,太麻烦,现在都是智能手机时代,wml模板已经不能 ...

  10. org.apache.commons.lang.StringUtils中常用的方法

    org.apache.commons.lang.StringUtils中常用的方法,这里主要列举String中没有,且比较有用的方法: 1. 检查字符串是否为空: static boolean isB ...