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.

<tex2html_verbatim_mark>

Input

The input consists of several test cases. The first line of each case contains two integers n<tex2html_verbatim_mark>(1n1000)<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 解题报告的更多相关文章

  1. POJ1328 Radar Installation 解题报告

    Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...

  2. POJ1328——Radar Installation

    Radar Installation Description Assume the coasting is an infinite straight line. Land is in one side ...

  3. ACM-ICPC 2017 Asia HongKong 解题报告

    ACM-ICPC 2017 Asia HongKong 解题报告 任意门:https://nanti.jisuanke.com/?kw=ACM-ICPC%202017%20Asia%20HongKon ...

  4. POJ 1328 Radar Installation 【贪心 区间选点】

    解题思路:给出n个岛屿,n个岛屿的坐标分别为(a1,b1),(a2,b2)-----(an,bn),雷达的覆盖半径为r 求所有的岛屿都被覆盖所需要的最少的雷达数目. 首先将岛屿坐标进行处理,因为雷达的 ...

  5. 贪心 + 计算几何 --- Radar Installation

    Radar Installation Description Assume the coasting is an infinite straight line. Land is in one side ...

  6. CH Round #56 - 国庆节欢乐赛解题报告

    最近CH上的比赛很多,在此会全部写出解题报告,与大家交流一下解题方法与技巧. T1 魔幻森林 描述 Cortana来到了一片魔幻森林,这片森林可以被视作一个N*M的矩阵,矩阵中的每个位置上都长着一棵树 ...

  7. 二模13day1解题报告

    二模13day1解题报告 T1.发射站(station) N个发射站,每个发射站有高度hi,发射信号强度vi,每个发射站的信号只会被左和右第一个比他高的收到.现在求收到信号最强的发射站. 我用了时间复 ...

  8. BZOJ 1051 最受欢迎的牛 解题报告

    题目直接摆在这里! 1051: [HAOI2006]受欢迎的牛 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4438  Solved: 2353[S ...

  9. 习题:codevs 2822 爱在心中 解题报告

    这次的解题报告是有关tarjan算法的一道思维量比较大的题目(真的是原创文章,希望管理员不要再把文章移出首页). 这道题蒟蒻以前做过,但是今天由于要复习tarjan算法,于是就看到codevs分类强联 ...

随机推荐

  1. python进阶3--文件系统

    文件系统 python的标准库中包括大量工具,可以处理文件系统中的文件,构造和解析文件名,也可以检查文件内容. pyhton表文件名表示为简单的字符串,另外还提供了一些工具,用来由os.path中平台 ...

  2. Groovy中那些神奇注解之InheritConstructors

    上一篇:Groovy中那些神奇注解之ToString 写完ToString,本来想今天就写到这了,突然觉得InheritConstructors注解实在也是个神器,写起来也没多少字,还是写了吧. In ...

  3. BZOJ 1177 [Apio2009]Oil(递推)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1177 [题目大意] 给出一个矩阵,从中选出3个k*k且不相交的矩阵,使得其总和最大 [ ...

  4. hdu 2563 统计问题

    统计问题 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissi ...

  5. C标准中一些预定义的宏

    C标准中指定了一些预定义的宏,对于编程经常会用到.下面这个表中就是一些常常用到的预定义宏. 宏(双下滑线) 意义 __DATE__ 进行预处理的日期(“Mmm dd yyyy”形式的字符串文字) __ ...

  6. Sql 字符串操作类COALESCE

    SqlServer中肯定有过将表中某列的值拼接成字符串,以","或者其他符号隔开的情况吧,一般情况我们会这样做: declare @returnValue nvarchar(max ...

  7. 笔记-Nodejs中的核心API之Events

    最近正在学习Node,在图书馆借了基本关于Node的书,同时在网上查阅资料,颇有收获,但是整体感觉对Node的理解还是停留在一个很模棱两可的状态.比如Node中的模块,平时练习就接触到那么几个,其他的 ...

  8. hdu 1251 统计难题(trie 树的简单应用)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给你多个字符串,求以某个字符串为前缀的字符串数量. 思路:简单的trie数应用,在trie ...

  9. BZOJ 2173: 整数的lqp拆分( dp )

    靠着暴力+直觉搞出递推式 f(n) = ∑F(i)f(n-i) (1≤i≤n) (直接想大概也不会很复杂吧...). f(0)=0 感受一下这个递推式...因为和斐波那契有关..我们算一下f(n)+f ...

  10. BZOJ 1770: [Usaco2009 Nov]lights 燈( 高斯消元 )

    高斯消元解xor方程组...暴搜自由元+最优性剪枝 -------------------------------------------------------------------------- ...