Radar Installation
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 52444 | Accepted: 11792 |
Description
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
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
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
题意:
给出 n(1 ~ 1000),d,后给出 n 个坐标点,问在 x 轴上选择一些点,这些点能覆盖周围半径 d 以内的地方,问最少在坐标轴上建立几个点,使之能覆盖所有给出的点,如果不能则输出 -1。
思路:
贪心。找出最少的点数,使之覆盖所有的区间。对于每个给出的点,在半径 d 以内都会在 x 轴上有一个区间范围,找出所有点的区间范围之后。题目变为求解找到最少的点使之所有区间得到覆盖的问题。先对所有区间范围的左坐标由小到大排序一遍,维护最右的端点值,如果下一个区间的左边大于当前右端点值,则需要增加一个点,且维护的最右端点值变为该区间的右端点值。还有一个值得注意的地方就是,如果这个区间的右端点值小于当前维护的右端点值,则需要更新这个端点值。如果在计算区间的时候,遇到 y > d 的则可以判断为 -1 输出。
AC:
#include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; typedef struct { double a, b; } node; node no[1005]; double dis (double a, double c) { double res = c * c - a * a; if(res < 0) return -1; return sqrt(res); } bool cmp (node a, node b) { return a.a < b.a; } int main() { int n, t = 0; double c; while (~scanf("%d%lf", &n, &c) && n && c) { int temp = 0; memset(no, 0, sizeof(no)); for (int i = 0; i < n; ++i) { double x, b; scanf("%lf%lf", &x, &b); if (b > c) temp = 1; else { double a = dis(b, c); no[i].a = x - a; no[i].b = x + a; } } printf("Case %d: ", ++t); if (temp) printf("-1\n"); else { sort(no, no + n, cmp); int ans = 1; double ee = no[0].b; for (int i = 1; i < n; ++i) { if (no[i].b < ee) ee = no[i].b; else if (no[i].a > ee) { ++ans; ee = no[i].b; } } printf("%d\n", ans); } } return 0; }
相关推荐
- **1360 Radar Installation**: 贪心算法在传感器覆盖问题上的应用。 - **1396 The Umbrella Problem: 2054**: 解决物品购买的决策问题,动态规划是关键。 - **1058 Currency Exchange**: 货币兑换问题,考虑图论中...
1360 Radar Installation 简单题 1396 The Umbrella Problem: 2054 简单题 1058 Currency Exchange 简单题 1076 Gene Assembly 简单题 1092 Arbitrage 简单题 1093 Monkey and Banana 简单题 1094 ...
1360 Radar Installation 简单题 1396 The Umbrella Problem: 2054 简单题 1058 Currency Exchange 简单题 1076 Gene Assembly 简单题 1092 Arbitrage 简单题 1093 Monkey and Banana 简单题 1094 ...
hi-z测试文件遮挡剔除
毕业设计-喝酒-整站商业源码.zip
生成对抗网络在计算机视觉领域的应用.pdf
内容概要:本文详细介绍了COMSOL在远场偏振通用计算中的应用,涵盖从建模到仿真的完整流程。首先解释了远场偏振的概念及其在光学模拟中的重要性,接着逐步讲解了如何在COMSOL中建立光学模型、划分网格、设置参数并运行仿真。随后,重点讨论了如何解读远场偏振图和能带结构图,最后介绍了如何使用Matlab程序读取COMSOL输出数据并进行进一步的分析和绘图。通过这些步骤,读者可以全面掌握COMSOL在远场偏振计算中的应用。 适合人群:从事光学仿真领域的研究人员和技术人员,尤其是那些希望深入了解COMSOL软件及其与Matlab集成使用的专业人士。 使用场景及目标:适用于需要进行复杂光学仿真和数据分析的研究项目,旨在提高对光波传播行为和材料特性的理解,促进相关领域的科研创新。 阅读建议:建议读者跟随文中提供的具体步骤进行实际操作练习,同时结合Matlab代码示例加深理解。对于初学者来说,可以从简单模型入手,逐渐过渡到更复杂的仿真任务。
07-组成原理1.3选择6-10.sz
SecureCRT-Portable安装包
内容概要:本文详细介绍了对传统DWA(Dynamic Window Approach)算法的改进,旨在解决机器人在复杂环境中遇到的问题。主要改进点包括:地图动态优化,允许通过图片形式加载并随时更换地图;引入自适应动态窗口策略,帮助机器人逃出C型障碍物等复杂地形的局部最优解;以及轨迹优化,使机器人的移动轨迹更优、更光滑、速度更快。实验结果显示,改进后的DWA算法在实际应用中表现出色,提高了机器人应对复杂环境的能力。 适合人群:从事机器人研究、开发及相关领域的科研人员和技术爱好者。 使用场景及目标:适用于需要在复杂环境中进行高效、安全导航的机器人系统,如无人驾驶车辆、自动导引车(AGV)等。目标是提升机器人在未知或变化环境中自主导航的能力。 其他说明:本文不仅提供了理论分析,还展示了具体的实现方法和效果对比,有助于读者深入理解改进措施及其带来的性能提升。
钉钉消息加密及批量推送系统1.0上线
液滴偏心碰撞的多体耗散粒子动力学研究.pdf
内容概要:本文详细介绍了在MATLAB R2018A环境中实现的一维时间序列信号同步压缩小波包变换算法。该算法通过引入同步压缩技术,显著提升了对信号瞬时成分的检测能力。文中不仅阐述了算法的基本原理和执行步骤,还展示了其在模拟信号和实际信号(如金融时间序列、地震信号、语音信号、声信号、生理信号等)中的具体应用实例。此外,文章讨论了算法的应用范围和迁移潜力,强调了其在多个领域的广泛应用前景。 适合人群:从事信号处理、数据分析及相关领域的研究人员和技术人员,尤其是那些熟悉MATLAB并希望深入了解小波包变换技术的人群。 使用场景及目标:适用于需要对一维时间序列信号进行高精度时频分析的研究项目。主要目标是提高对信号瞬时成分的检测能力和提取有用的特征信息,从而为后续的数据处理和分析提供坚实的基础。 其他说明:该算法不仅可以应用于现有的MATLAB环境,还可以迁移到其他类似平台,进一步扩展其应用场景。同时,文中提供的代码示例和参数设置指南有助于读者快速上手并深入理解算法的工作机制。
内容概要:本文详细介绍了构网变流器在dq坐标系下的功率控制技术,重点探讨了下垂控制、无功下垂比例积分控制以及电压电流双闭环和电压前馈技术。通过这些技术手段,可以实现功率的准确、快速无静差跟踪和电压的高精度跟踪。文中还展示了具体的控制算法和伪代码示例,解释了如何利用PID和PI控制器调整系统参数,确保电力系统的稳定性和高效运行。 适合人群:从事电力电子系统研究与开发的技术人员,尤其是关注构网变流器功率控制领域的工程师和研究人员。 使用场景及目标:适用于需要优化电力系统性能的实际工程应用场景,旨在提高电力传输的稳定性、可靠性和效率。目标是帮助技术人员理解和掌握先进的功率控制技术,提升系统设计能力。 其他说明:随着电力电子技术的发展,新的控制策略和算法不断涌现,未来的研究将继续探索更高性能的解决方案,以应对更加复杂的电力系统需求。
MAX31865.PDF
软考初级程序员相关文档
dify离线插件
毕业设计-封装免签版苹果APP-整站商业源码.zip
打造 Python 安装使用教程,涵盖下载安装、入门操作及基础算法应用,详解环境搭建与实操技巧,助你快速掌握 Python,无论是编程新手还是想强化技能者,都能借此轻松提升,开启高效编程之旅。
毕业设计-活动报名4.2.6+年卡1.1.7 全开源-整站商业源码.zip