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 简述:每个island与X轴都有最多2个交点,求最少点满足与所有区间相交
思路:区间选点问题,将每个区间右边递增排序后寻找即可,代码如下:
#define sqr(x) ((x)*(x))

const int maxm = ;

struct Node {
double l, r;
bool operator< (const Node &a) const {
return r < a.r;
}
} Nodes[maxm]; int d, n, sum, kase = ; int main() {
while(scanf("%d%d", &n, &d) && n) {
printf("Case %d: ", ++kase);
bool flag = true;
sum = ;
for (int i = ; i < n; ++i) {
double tx, ty, tmp;
scanf("%lf%lf", &tx, &ty); //x = tx -+ sqrt(d^2 - y0 ^2 )
if(d < ty) {
flag = false;
sum = -;
}
tmp = sqrt(sqr(d) - sqr(ty));
Nodes[i].l = tx - tmp, Nodes[i].r = tx + tmp;
}
if(flag) {
sort(Nodes, Nodes + n);
double maxr = Nodes[].r;
for (int i = ; i < n; ++i) {
if(maxr < Nodes[i].l) {
maxr = Nodes[i].r;
++sum;
}
}
}
printf("%d\n", sum);
}
return ;
}

注意在判断ty>d的时候不能提前退出,要读取完

补:

在区间选点问题上,要右端点进行排序,因为要找一个现有区间的公共点,若是左端点,会出现漏解的情况,例如:

												

Day3-C-Radar Installation POJ1328的更多相关文章

  1. [POJ1328]Radar Installation

    [POJ1328]Radar Installation 试题描述 Assume the coasting is an infinite straight line. Land is in one si ...

  2. POJ1328——Radar Installation

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

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

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

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

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

  5. 【贪心】「poj1328」Radar Installation

    建模:二维转一维:贪心 Description Assume the coasting is an infinite straight line. Land is in one side of coa ...

  6. POJ1328 Radar Installation 解题报告

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

  7. POJ 1328 Radar Installation 贪心 A

    POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...

  8. Radar Installation

    Radar Installation 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/C 题目: De ...

  9. Radar Installation(贪心)

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

  10. 贪心 POJ 1328 Radar Installation

    题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...

随机推荐

  1. JavaSE复习~Java语言发展史

    Java概述 什么是Java语言? Java语言是美国Sun公司(Stanford University NetWork),在1995年推出的高级编程语言. 所谓编程语言,是计算机的语言,人们可以使用 ...

  2. openfire 安装配置时出现The Openfire database schema does not appear to be installed. Follow the installati错误的解决方案

    最近再弄openfire用openLDAP整合,本来没整合的时候选的标准数据库没问题,但是现在用嵌入式数据库,就报错了,,, 报错原因:没有导入openfire的数据表 解放办法: 1.登陆数据库 , ...

  3. Nexus-vPC基础实验

    一.实验拓扑: 由于条件有限,使用两个N5K做基本的vPC实验,Peer Keepalive Link使用的是两个Nexus 5K的Mgm0接口. 二.配置步骤:1.先构建vPC domain,并在d ...

  4. codeforces Round #611

    这种凌晨场真的折寿 就过了四题,8wa结尾心态炸裂,求别被hack,再hack就要爬了 A2   B8   C38(1)   E1:58(7) D题感觉可以写,但是没有时间看了.幸好E最后发现了自己的 ...

  5. 各大厂商发力5G新机,未来全球手机市场或将呈现新格局

    随着5G商用将正式于今年开启落地,运营商和手机厂商都在为新一代网络制式积极做好准备.对于运营商来说,它们在不断增加5G基站的建设,让5G信号覆盖更广泛的范围.而对于手机厂商来说,它们在努力推出旗下的5 ...

  6. MUI - 上拉加载不执行

    mui('#pullrefresh').pullRefresh().refresh(true); if($(".list-item").length == countDataSum ...

  7. JDBC笔记一

    连接池原理 数据库连接池:1.提前创建好多个连接对象,放到缓存中(集合),客户端用时直接从缓存中获取连接 ,用完连接后一定要还回来. 目的:提高数据库访问效率.  模拟代码: package com. ...

  8. mysql之魔鬼训练营

    普通 + 中等 难度练习题 测试数据: --建表 --学生表 CREATE TABLE `Student`( `s_id` VARCHAR(20), `s_name` VARCHAR(20) NOT ...

  9. #P1099 树网的核 题解

    题目描述 pdf 题解 这一题,刚开始看题目感觉好像很难,题目又长……一看数据范围,呵呵. 已经给出来这是个DAG,所以不用担心连通性的问题.那么怎么做呢? 朴素的做法是把树的直径的两个端点都统计出来 ...

  10. Codeforces1307C. Cow and Message

    读题,我们知道选1个.选2个的时候是没有冲突的,大于2个的时候就有限制,那么我们观察是否可以把大于2个的情况都转换一下,可以发现,如果有一个串的长度大于2,且出现的次数大于2,那么,组成这个串里必定有 ...