hdoj Radar Installation
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.
Figure A Sample Input of Radar Installations
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
3 2
1 2
-3 1
2 1 1 2
0 2 0 0
Case 1: 2
Case 2: 1#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
struct node
{
float l,r,x,y;
}d[1100];
int cmp(node x,node y)
{
return x.l<y.l;/*按照区域的最左端排序*/
}
int main()
{
int sum,t,m,n,flog=1,Case=1,i,num,j;
while(scanf("%d%d",&m,&n),m||n)
{
for(i=0;i<m;i++)
{
scanf("%f%f",&d[i].x,&d[i].y);
if(d[i].y>n)
{
flog=0;break;
}
else
{
d[i].l=d[i].x-sqrt(n*n-d[i].y*d[i].y);/*求出雷达的扫描区域*/
d[i].r=d[i].x+sqrt(n*n-d[i].y*d[i].y);
}
}
printf("Case %d: ",Case);
if(flog==0) printf("-1\n");
else
{
int sign=0;num=0;
sort(d,d+m,cmp);
num++;sign=d[0].r;/*这个很重要,sign始终标记雷达所能扫描的最右端*/
for(i=1;i<m;i++)/*至少设置一个雷达,如果当前判断的区域达不到雷达最右端,加设一个雷达*/
{
if(d[i].r<sign)
sign=d[i].r;
else if(d[i].l>sign)
{
num++;sign=d[i].r;
}
}
printf("%d\n",num);
}
}
return 0;
}
hdoj Radar Installation的更多相关文章
- [POJ1328]Radar Installation
[POJ1328]Radar Installation 试题描述 Assume the coasting is an infinite straight line. Land is in one si ...
- Radar Installation
Radar Installation 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/C 题目: De ...
- Radar Installation(贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 56826 Accepted: 12 ...
- 贪心 POJ 1328 Radar Installation
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...
- Radar Installation 分类: POJ 2015-06-15 19:54 8人阅读 评论(0) 收藏
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 60120 Accepted: 13 ...
- poj 1328 Radar Installation(nyoj 287 Radar):贪心
点击打开链接 Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43490 Accep ...
- Poj 1328 / OpenJudge 1328 Radar Installation
1.Link: http://poj.org/problem?id=1328 http://bailian.openjudge.cn/practice/1328/ 2.Content: Radar I ...
- POJ1328——Radar Installation
Radar Installation Description Assume the coasting is an infinite straight line. Land is in one side ...
- poj 1328 Radar Installation【贪心区间选点】
Radar Installation Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) ...
随机推荐
- VC窗口类的销毁-是否需要delete
Windows窗口如果使用new的方法添加之后,在父窗口析构的时候,有些需要delete有些却不需要delete.这个的确有点坑,由于c++的实现,对于每个自己new的对象,我都会delete删除它, ...
- Hive扩展功能(六)--HPL/SQL(可使用存储过程)
软件环境: linux系统: CentOS6.7 Hadoop版本: 2.6.5 zookeeper版本: 3.4.8 主机配置: 一共m1, m2, m3这五部机, 每部主机的用户名都为centos ...
- JS高级——作用域链
基本概念 1.只要是函数就可以创造作用域 2.函数中又可以再创建函数 3.函数内部的作用域可以访问函数外部的作用域 4.如果有多个函数嵌套,那么就会构成一个链式访问结构,这就是作用域链 <scr ...
- C# 处理URL地址
calendarset.do?start=1548518400&end=1552147200&_=1546421856958calendarset.do?start=155093760 ...
- 如何让git忽略指定的文件
有些文件,我们修改后,并不需要git提交更改,可以在.gitignore里面设置过滤规则 在.gitignore文件里面输入 *.zip 表示所有zip文件忽略更改 /bin 表示忽略整个根目录的bi ...
- 三年半Java后端面试鹅厂,三面竟被虐的体无完肤
经过半年的沉淀,加上对MySQL,redis和分布式这块的补齐,终于开始重拾面试信心,再次出征. 鹅厂 面试职位: go后端开发工程师,接受从Java转语言 都知道鹅厂是cpp的主战场,而以cpp为背 ...
- jquery动态生成二维码添加自定义logo
动态生成二维码中间带logo. jquery.qrcode.js 动态生成二维码api很简单. 引入jquer(版本任意),引入jquery.qrcode.js 不需要中间带logo这样就可以了.带l ...
- 使用jquery将表单自动封装成json对象 /json对象元素的添加删除和转换
$.fn.serializeObject = function () { var o = {}; var a = this.serializeArray(); $.each(a, function ( ...
- uva 1585 Score(Uva-1585)
vj:https://vjudge.net/problem/UVA-1585 不多说水题一个o一直加x就加的变为0 我的代码 #include <iostream> #include &l ...
- hdu 2782 dfs(限定)
The Worm Turns Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...