C-C Radar Installation 解题报告
C-C Radar Installation 解题报告
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/C
题目:
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<tex2html_verbatim_mark> distance, so an island in the sea can be covered by a radius installation, if the distance between them is at most d<tex2html_verbatim_mark> .
We use Cartesian coordinate system, defining the coasting is the x<tex2html_verbatim_mark> -axis. The sea side is above x<tex2html_verbatim_mark> -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<tex2html_verbatim_mark> - y<tex2html_verbatim_mark> coordinates.
Input
The input consists of several test cases. The first line of each case contains two integers n<tex2html_verbatim_mark>(1n
1000)<tex2html_verbatim_mark> and d<tex2html_verbatim_mark> , where n<tex2html_verbatim_mark> is the number of islands in the sea and d<tex2html_verbatim_mark> is the distance of coverage of the radar installation. This is followed by n<tex2html_verbatim_mark> 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 2
1 2
-3 1
2 1 1 2
0 2 0 0
Sample Output
Case 1: 2
Case 2: 1
题目大意:
在一条海岸线的一侧有若干个岛屿,将海岸线看成是X轴,X轴以上是大海,在海岸上安装雷达使其能覆盖全部岛屿,给出雷达的覆盖半径和岛屿位置,求最少使用多少
雷达才能将所有岛屿全部覆盖。无法覆盖输出-1. 分析:
1.可以换一种想法,求雷达覆盖小岛就是以小岛为圆心,雷达的覆盖半径为半径画圆
2.小岛到海岸线的距离大于半径,不能覆盖所有小岛,输出-1
3.若小于半径,该圆与X轴的左交点为line[i].l=(double)x-sqrt((double)d*d-y*y);右交点为 line[i].r=(double)x+sqrt((double)d*d-y*y);
4.将左交点排序,判断雷达位置,如果i点的左交点在当前雷达的右边,需要安装一个新雷达;如果i点的右交点在当前雷达的左边,则把当前雷达的圆心更新为该点的右交点 代码:
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn=; struct Line //每个岛作半径为d的圆,与x轴所截的线段
{
double l,r;
}line[maxn]; bool cmp(Line a,Line b)//按照线段的左端点从小到大排序
{
return a.l<b.l;
} int main()
{
int n,d;
int i;
int x,y;
bool yes;//确定是不是有解
int m=;
while(scanf("%d%d",&n,&d)!=EOF)
{
yes=true;
int cnt=;
if(n==&&d==) //n,d均为0,程序结束
break;
for(i=;i<n;i++)
{
scanf("%d%d",&x,&y);
if(yes==false)
continue;
if(y>d)
yes=false;
else
{
line[i].l=(double)x-sqrt((double)d*d-y*y);
line[i].r=(double)x+sqrt((double)d*d-y*y);
}
}
if(yes==false) //不能完全覆盖
{
printf("Case %d: -1\n",m++);
continue;
}
sort(line,line+n,cmp);//排序
cnt++;
double now=line[].r;
for(i=;i<n;i++)
{
if(line[i].r<now) //与现在比较,这个很重要
now=line[i].r;
else if(now<line[i].l)
{
now=line[i].r;
cnt++;
}
}
printf("Case %d: %d\n",m++,cnt);
} return ;
}
C-C Radar Installation 解题报告的更多相关文章
- POJ1328 Radar Installation 解题报告
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- POJ1328——Radar Installation
Radar Installation Description Assume the coasting is an infinite straight line. Land is in one side ...
- ACM-ICPC 2017 Asia HongKong 解题报告
ACM-ICPC 2017 Asia HongKong 解题报告 任意门:https://nanti.jisuanke.com/?kw=ACM-ICPC%202017%20Asia%20HongKon ...
- POJ 1328 Radar Installation 【贪心 区间选点】
解题思路:给出n个岛屿,n个岛屿的坐标分别为(a1,b1),(a2,b2)-----(an,bn),雷达的覆盖半径为r 求所有的岛屿都被覆盖所需要的最少的雷达数目. 首先将岛屿坐标进行处理,因为雷达的 ...
- 贪心 + 计算几何 --- Radar Installation
Radar Installation Description Assume the coasting is an infinite straight line. Land is in one side ...
- CH Round #56 - 国庆节欢乐赛解题报告
最近CH上的比赛很多,在此会全部写出解题报告,与大家交流一下解题方法与技巧. T1 魔幻森林 描述 Cortana来到了一片魔幻森林,这片森林可以被视作一个N*M的矩阵,矩阵中的每个位置上都长着一棵树 ...
- 二模13day1解题报告
二模13day1解题报告 T1.发射站(station) N个发射站,每个发射站有高度hi,发射信号强度vi,每个发射站的信号只会被左和右第一个比他高的收到.现在求收到信号最强的发射站. 我用了时间复 ...
- BZOJ 1051 最受欢迎的牛 解题报告
题目直接摆在这里! 1051: [HAOI2006]受欢迎的牛 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4438 Solved: 2353[S ...
- 习题:codevs 2822 爱在心中 解题报告
这次的解题报告是有关tarjan算法的一道思维量比较大的题目(真的是原创文章,希望管理员不要再把文章移出首页). 这道题蒟蒻以前做过,但是今天由于要复习tarjan算法,于是就看到codevs分类强联 ...
随机推荐
- MySQL 设置数据库的隔离级别
在会话级别设置隔离级别 1.read commited :set session transaction isolation level read committed; 2.repeatable re ...
- Android中自定义属性的使用
做Android布局是件很享受的事,这得益于他良好的xml方式.使用xml可以快速有效的为软件定义界面.可是有时候我们总感觉官方定义的一些基本组件不够用,自定义组件就不可避免了.那么如何才能做到像官方 ...
- CCNP路由实验(3) -- 路由控制
1.用distribute-list过滤路由在不同协议里的用法 在RIP里 在EIGRP里 在OSPF里 只接收奇数路由 只接收偶数路由 只接收被4整除的路由2.offset-list在不同协议里的用 ...
- addEventlistener监听的事件完成一次后自动取消与jquery的one方法比较;animate动画制作,arguments.callee的用法
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- visual studio2013负载测试简单问题记录
问题1: 错误 xxxx/xx/xx xx:xx:xx 未能对测试运行“xxxxxxxxxxx”进行排队: 活动的测试设置配置为使用 Visual Studio Online 运行测试. 使用团队资源 ...
- iOS 图标、图形尺寸? iPhone、iPad、 iPod touch
链接地址:http://www.zhihu.com/question/20248971 著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:刘剑链接:http://www.zhi ...
- 1.4. chromium源代码分析 - chromiumframe - 消息系列
Message framework 是对消息循环的封装和扩展,Chromium在消息循环中增加处理内部任务的工作.将内部工作处理寄生在Windows的消息循环中,会有一个问题,就是没有Windows自 ...
- 数据可视化开源系统(python开发)
Caravel 是 Airbnb (知名在线房屋短租公司)开源的数据探查与可视化平台(曾用名Panoramix),该工具在可视化.易用性和交互性上非常有特色,用户可以轻松对数据进行可视化分析. 核心功 ...
- Java "==和equals区别"
本文转载至中软国际电子政务部Jeff Chi总结,转载请说明出处. 概述: A.==可用于基本类型和引用类型:当用于基本类型时候,是比较值是否相同:当用于引用类型的时候,是比较对象是否相 ...
- Struts2,Spring,Hibernate三大框架的整合(SSH)
一.搭建struts2 1).导入struts2 jar包 2).编写web.xml 3).编写jsp页面 4).创建action类,action类要继承ActionSupport类 5).创建str ...