博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Radar Installation
阅读量:6856 次
发布时间:2019-06-26

本文共 2984 字,大约阅读时间需要 9 分钟。

Radar Installation
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB
Total submit users: 562, Accepted users: 500
Problem 10023 : No special judgement
Problem 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. 
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 21 2-3 12 11 20 20 0
Sample Output
Case 1: 2Case 2: 1
Problem Source
Bei jing 2002

解题思路:

radar installation

在海里有很多小岛,每个小岛位置由x,y坐标确定。而我们只能在海岸线上建雷达站,同时给定雷达站的最大覆盖距离d(以雷达站为圆心,d为半径),要求所有小岛都要被雷达站覆盖,求最少的雷达站数目,如果没有解决方案,输出-1。

 

贪心策略1:让某个雷达站覆盖尽量多的小岛?--》不正确

贪心策略2:从左往右建雷达站:最左边的雷达站需要覆盖最左边的小岛,同时位置尽量右靠。依次重复。
1. 如何确定雷达可能位置:以小岛为圆心,画圆,与海岸线的右交点为建雷达站点。
2. 对于所有小岛,求出左右交点,从左至右,以第一个右交点为基准,
如果下一海岛的左交点小于或等于该右交点,则此海岛能够被该雷达站覆盖,
不过这里要注意,如果出现该海岛的右交点小于或该右交点的情况,基准应该换成该海岛的右交点;
如果下一海岛的左交点大于该右交点,则需要新建雷达站,雷达站数++,同时以这一海岛的右交点为基准,重复上步骤;

 

代码(C++):

#include
#include
#include
using namespace std;struct node{ double left,right;//以每个岛为圆心,与x轴的左右交点 }island[1001];//1001个实例 //sort的比较函数 bool cmp(node a,node b){ return a.left
>n>>d && n!=0){ CaseNum++; flag=0; //输入,并记录island.left 和island.right for(int i=0;i
>x>>y; //如果小岛到x轴的距离y大于d,则没有解决方案 if(y>d) { flag=1;//没有解决方案 } //记录以每个小岛为圆心,d为半径的圆与x轴的左右交点 island[i].left=x-sqrt(d*d-y*y); island[i].right=x+sqrt(d*d-y*y); } //没有解决方案 if(flag==1) { cout<<"Case "<
<<": -1"<
tmp){ count++; tmp=island[i].right; } else if(island[i].right

 

转载于:https://www.cnblogs.com/Hazel-97/p/7921365.html

你可能感兴趣的文章
网站安全监测 - Node实战
查看>>
开源公司内部的微信爬虫,寻求志同道合的人一起来改进
查看>>
重写yii2的数据提供器ArrayDataProvider类
查看>>
[译] Webpack 前端构建集成方案
查看>>
gulp-livereload实战应用
查看>>
mac和linux下mysql字符集设置问题
查看>>
如何直接访问github的html项目
查看>>
Scala 简介 [摘自 Scala程序设计 ]
查看>>
NodeJs sprity在window下使用的问题整理
查看>>
Numpy 中文用户指南 3.2 创建数组
查看>>
Docker 监控之 SaaS 解决方案
查看>>
HTTP权威指南:第三章
查看>>
javascript函数式编程入门小结
查看>>
KindEditor 上传漏洞致近百个党政机关网站遭植入
查看>>
迈入Docker、Kubernetes容器世界的大门
查看>>
mysql之调优概论
查看>>
Guidelines for Function Compute Development - Troubleshoot Timeout ...
查看>>
记一次JVM调优
查看>>
SAP的BADI类型增强的学习方法
查看>>
Spark2.4.0 Dataset head 源码分析
查看>>