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 程序中设置环境变量

    python 中调用系统命令有三种方法: 1.os.system('command') ,这个方法是直接调用标准C的system() 函数,仅仅在一个子终端运行系统命令,而不能获取命令执行后的返回信息 ...

  2. Linux同平台Oracle数据库整体物理迁移

    Linux同平台数据库整体物理迁移需求:A机器不再使用,要将A机器的Oracle迁移到B机器.之前写过类似需求的文章: http://www.linuxidc.com/Linux/2015-05/11 ...

  3. Codeforces 711E ZS and The Birthday Paradox(乘法逆元)

    [题目链接] http://codeforces.com/problemset/problem/711/E [题目大意] 假设一年有2^n天,问k个小朋友中有两个小朋友生日相同的概率. 假设该概率约分 ...

  4. POJ 3693 Maximum repetition substring(后缀数组+ST表)

    [题目链接] poj.org/problem?id=3693 [题目大意] 求一个串重复次数最多的连续重复子串并输出,要求字典序最小. [题解] 考虑错位匹配,设重复部分长度为l,记s[i]和s[i+ ...

  5. JqGrid使用经验

    一.更改分页组件的样式 分页组件中

  6. Please ensure that adb is correctly located at '...adb.exe' and can be executed.

    Android Launch! The connection to adb is down, and a severe error has occured. You must restart adb ...

  7. display:table标签来自动改变列宽 改变的同时table的整体宽度跟随变化

    发现公司里的所有分页功能都是通过display:talbe来实现的,但是用户最近说要让表格列宽可以拖动:所有我就寻找了好多的办法:网上找了很多的资料,但是都不是我要的效果因为他们都是列宽不改变要不就是 ...

  8. Linux特殊权限:SUID、SGID、SBIT

    SUID:      只对二进制程序有效      执行者对于程序需要有x权限      在程序运行过程中,执行者拥有程序拥有者的权限      例如:      普通用户执行passwd命令.   ...

  9. [每日一题] 11gOCP 1z0-052 :2013-09-10 ABOUT ALERTS...............................................A50

    转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/11546561 正确答案:AD 使用服务器生成的警报系统,从Oracle10g版本开始,Or ...

  10. ios数组基本用法和排序

    1.创建数组 // 创建一个空的数组 NSArray *array = [NSArray array]; // 创建有1个元素的数组 array = [NSArray arrayWithObject: ...