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

本文共 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

你可能感兴趣的文章
Facebook通过10亿单词构建有效的神经网络语言模型
查看>>
发展大数据不能抛弃“小数据”
查看>>
中了WannaCry病毒的电脑几乎都是Win 7
查看>>
学生机房虚拟化(九)系统操作设计思路
查看>>
nginx报错pread() returned only 0 bytes instead of 4091的分析
查看>>
质数因子
查看>>
Spring源码浅析之事务(四)
查看>>
[转载] Live Writer 配置写 CSDN、BlogBus、cnBlogs、163、sina 博客
查看>>
SQL:连表查询
查看>>
MySQL日期函数、时间函数总结(MySQL 5.X)
查看>>
c语言用尾插法新建链表和输出建好的链表
查看>>
高性能 Oracle JDBC 编程
查看>>
java 中ResultSet可以获取的数据类型及返回值类型列表
查看>>
ubuntu 13 安装SH程序
查看>>
支付宝升级延时到账功能
查看>>
ghost后只剩下一个盘的数据寻回方法
查看>>
输入输出练习
查看>>
Git commit message和工作流规范
查看>>
java面试。答案源于网上
查看>>
yii中取得CActiveDataProvider的分页信息
查看>>