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 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...
随机推荐
- sso系统登录以及jsonp原理
登录的处理流程: 1.登录页面提交用户名密码. 2.登录成功后生成token.Token相当于原来的jsessionid,字符串,可以使用uuid. 3.把用户信息保存到redis.Key就是toke ...
- Spring Boot Security 使用教程
虽然,我在实际项目中使用的是 shiro 进行权限管理,但 spring boot security 早已大名鼎鼎,虽然他的入门要相对复杂一点,但是设计视乎更加吸引人. 本章节就是以一篇快速入门 sp ...
- 802.1X高级配置
部署VLAN和ACLCisco Catalyst交换机(认证方)和Cisco ACS(认证服务器)具备动态分配VLAN或者ACL的能力.Cisco ACS可以将某个用户分配给指定的VLAN,或应用AC ...
- Myeclipse下PHP开发环境搭建及运行
外接CSDN链接 http://blog.csdn.net/yuxiangaaaaa/article/details/54948426 这是php初始设置,后面进行重新设置
- pytoch 安装
注意替换清华源,否则直接安装速度会很慢. conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud ...
- SqlServer游标操作
CLOSE orderNum_02_cursordeallocate orderNum_02_cursorDECLARE orderNum_02_cursor cursor SCROLL for se ...
- FTP文件传输服务!
一.FTP 连接及传输模式 1.控制连接:TCP 21,用于发送 FTP 命令信息2.数据连接:TCP 20,用于上传.下载数据3.数据连接的建立类型: (1)主动模式:服务器主动发起数据连接 (2 ...
- 「luogu3402」【模板】可持久化并查集
「luogu3402」[模板]可持久化并查集 传送门 我们可以用一个可持久化数组来存每个节点的父亲. 单点信息更新和查询就用主席树多花 一个 \(\log\) 的代价来搞. 然后考虑如何合并两个点. ...
- 为PHP开发搭建环境
为了能在自己的电脑上(mac OS系统)开始编写PHP代码并完成运行,需要有: 1.安装Web服务器 2.安装PHP 3.安装数据库,比如MySQL 4.一个PHP的IDE 为了上面所提到的1~3步的 ...
- Gof 设计模式
设计模式的用途(参考) 设计模式代表了最佳实践,通常被有经验的面向对象的软件开发人员采用.设计模式是软件开发人员在软件开发过程中面临一般问题的解决方案.这些解决方案是众多软件开发人员在相当长的时间的实 ...