[POJ1328]Radar Installation
[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的更多相关文章
- POJ1328——Radar Installation
Radar Installation Description Assume the coasting is an infinite straight line. Land is in one side ...
- POJ--1328 Radar Installation(贪心 排序)
题目:Radar Installation 对于x轴上方的每个建筑 可以计算出x轴上一段区间可以包含这个点 所以就转化成 有多少个区间可以涵盖这所有的点 排序之后贪心一下就ok 用cin 好像一直t看 ...
- POJ1328 Radar Installation 【贪心·区间选点】
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 54593 Accepted: 12 ...
- POJ1328 Radar Installation 解题报告
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- poj1328 Radar Installation(贪心 策略要选好)
https://vjudge.net/problem/POJ-1328 贪心策略选错了恐怕就完了吧.. 一开始单纯地把island排序,然后想从左到右不断更新,其实这是错的...因为空中是个圆弧. 后 ...
- POJ1328 Radar Installation(贪心)
题目链接. 题意: 给定一坐标系,要求将所有 x轴 上面的所有点,用圆心在 x轴, 半径为 d 的圆盖住.求最少使用圆的数量. 分析: 贪心. 首先把所有点 x 坐标排序, 对于每一个点,求出能够满足 ...
- zoj1360/poj1328 Radar Installation(贪心)
对每个岛屿,能覆盖它的雷达位于线段[x-sqrt(d*d-y*y),x+sqrt(d*d+y*y)],那么把每个岛屿对应的线段求出来后,其实就转化成了经典的贪心法案例:区间选点问题.数轴上有n个闭区间 ...
- poj1328 Radar Installation —— 贪心
题目链接:http://poj.org/problem?id=1328 题解:区间选点类的题目,求用最少的点以使得每个范围都有点存在.以每个点为圆心,r0为半径,作圆.在x轴上的弦即为雷达可放置的范围 ...
- ZOJ-1360 || POJ-1328——Radar Installation
ZOJ地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=360 POJ地址:http://poj.org/problem?id ...
随机推荐
- mysql dump
mysqldump wifi3 > wifi3.sql mysqldump wifi3 < wifi3.sql
- idea community 配置已有的scala工程
- 蛋疼的vs
这个vs2008 难用的很,要是叫我选肯定vs高版本的,vs2012或者直接vs2015
- 爬虫4 html输出器 html_outputer.py
#coding:utf8 __author__ = 'wang' class HtmlOutputer(object): def __init__(self): self.datas = []; de ...
- Div内有ul li元素,Div设置高度100%,谷歌IE下li过多会显示滚动条,而火狐下就会滚动条就不起作用,li会撑大Div
产品上也许是用了过多iframe问题,自己做了demo没有这种情况 解决办法: 设置Div的display样式为-moz-inline-grid -moz-代表火狐私有属性,使用自己的div样式就可以 ...
- CodeLite的姿势
在Mac上安装cscope 1.下载cscope的Zip压缩包 2.解压 3.打开终端,进入解压目录,运行 ./configure make make install 4.在CodeLite中,在Pl ...
- input 获取当前id,name
<input name=" src="toright.png" value="mp3"> <script language=&quo ...
- Bitcask 存储模型
Bitcask 存储模型 Bitcask 是一个日志型.基于hash表结构的key-value存储模型,以Bitcask为存储模型的K-V系统有 Riak和 beansdb新版本. 日志型数据存储 何 ...
- Thinkphp 连接查询的使用
方法一:使用table()方法 $tables = 'b_order ordert, b_busbid busbid'; $map['busbid.buscompanyid'] = 1; $map[' ...
- jQuery 遍历 - find() 方法
实例 搜索所有段落中的后代 span 元素,并将其颜色设置为红色: $("p").find("span").css('color','red'); 详情:htt ...