Day3-C-Radar Installation POJ1328
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 is terminated by a line containing pair of zeros
Output
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的更多相关文章
- [POJ1328]Radar Installation
[POJ1328]Radar Installation 试题描述 Assume the coasting is an infinite straight line. Land is in one si ...
- 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 coa ...
- POJ1328 Radar Installation 解题报告
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- POJ 1328 Radar Installation 贪心 A
POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...
- Radar Installation
Radar Installation 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/C 题目: De ...
- Radar Installation(贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 56826 Accepted: 12 ...
- 贪心 POJ 1328 Radar Installation
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...
随机推荐
- docker环境下mysql数据库的备份
#! /bin/bash DATE=`date +%Y%m%d%H%M%S` BACK_DATA=erp-${DATE}.sql #导出表结构,不包括表数据 #docker exec -i xin-m ...
- Android、iOS与Servlet接口上传文件和JSON串的交互
package etcom.servlet; import java.io.File; import java.io.IOException; import java.sql.Connection; ...
- 涂涂影院APP-免费VIP电影观看「安卓APP」
最新下载链接:https://www.lanzous.com/u/niceyoo 2019年基本就没推广过这款APP,很失败,从第一版发布到现在涂涂影院已经做了2年了, 由于没有官网,所以基本百度能搜 ...
- cmd设置utf8编码
在中文windows系统中,如果一个文本文件是utf-8编码的,那么在cmd.exe命令行窗口(所谓的dos窗口)中不能正确显示文件中的内容.在默认情况下,命令行窗口中使用的代码页是中文或者美国的,即 ...
- 自定义Redis作为Session存储服务提供
之前看网上介绍可使用Redis自定义Session托管,使用第三方的Harbour.RedisSessionStateStore GitHub:https://github.com/TheCloudl ...
- 【协作式原创】查漏补缺之Golang中mutex源码实现(预备知识)
预备知识 CAS机制 1. 是什么 参考附录3 CAS 是项乐观锁技术,当多个线程尝试使用 CAS 同时更新同一个变量时,只有其中一个线程能更新变量的值,而其它线程都失败,失败的线程并不会被挂起,而是 ...
- elk安装2.0版本,自己总结,比较细致 es单机的安装
用root用户会报错,版本6之前还是可以用root用户启动的,针对es的保护,数据的一些问题,6之后就不允许了. 启动成功 下面验证一下 可以直接用浏览器访问,接受http访问 配置,因为没有暴露端 ...
- python字典中值为列表或字典的构造方式
1.值为列表的构造方法 dic = {} dic.setdefault(key,[]).append(value) >>dic.setdefault('a',[]).append(1) & ...
- Windows 10 20H1版名称被定为Windows 10 Version 2004版以示区分
导读 我们知道Windows 10 20H1 版目前的开发工作已经接近完成,当前微软主要通过新版本来修复部分已知的问题. 而名称上面按照以往规律推算应该是 Windows 10 Version 200 ...
- MPAndroidChart柱子上的文字的颜色dataSet.setValueTextColors
版本:MPAndroidChart v3.1.0 这是个很强大的图表,不同的版本对应的API会不一样. 需求描述: 用了柱状图,但要实现这样的功能,通过不同的门店来区分不同的柱子的颜色,并且柱子上文字 ...