贪心 Radar Installation (求最少探测雷达)
Description
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
Input
The input is terminated by a line containing pair of zeros
Output
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坐标范围,b为雷达探测半径,岛的坐标为(x,y),雷达的坐标范围是(x-sqrt(d*d-y*y),x+sqrt(d*d-y*y)),定义sum=1,i从1开始,每个坐标范围左右边界与上一个坐标范围的右边界比较,具体看代码。
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
struct stu
{
double l,r;
} st[];
bool cmp(stu a,stu b)
{
return a.l<b.l;
}
int main()
{
int a,s,k=,sum,i;
double b,x,y,sky;
while(scanf("%d %lf",&a,&b) &&!(a==&&b==))
{
s=;
k++;
for(i = ; i < a ; i++)
{
scanf("%lf %lf",&x,&y);
if(b < || y > b)
{
s=-;
}
st[i].l=x-sqrt(b*b-y*y);
st[i].r=x+sqrt(b*b-y*y);
}
if(s == -) printf("Case %d: -1\n",k);
else
{
sort(st,st+a,cmp);
sum=;
sky=st[].r;
for(i = ; i < a ; i++)
{
if(st[i].r <= sky)
{
sky=st[i].r;
}
else
{
if(st[i].l > sky)
{
sky=st[i].r;
sum++;
}
}
}
printf("Case %d: %d\n",k,sum);
} }
}
贪心 Radar Installation (求最少探测雷达)的更多相关文章
- [ACM_贪心] Radar Installation
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28415#problem/A 题目大意:X轴为海岸线可放雷达监测目标点,告诉n个目标点和雷 ...
- 贪心 POJ 1328 Radar Installation
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...
- POJ 1328 Radar Installation 【贪心 区间选点】
解题思路:给出n个岛屿,n个岛屿的坐标分别为(a1,b1),(a2,b2)-----(an,bn),雷达的覆盖半径为r 求所有的岛屿都被覆盖所需要的最少的雷达数目. 首先将岛屿坐标进行处理,因为雷达的 ...
- poj 1328 Radar Installation (简单的贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42925 Accepted: 94 ...
- Radar Installation POJ - 1328(贪心)
Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. ...
- poj 1328 Radar Installation(贪心+快排)
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- POJ 1328 Radar Installation(很新颖的贪心,区间贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 106491 Accepted: 2 ...
- 【OpenJ_Bailian - 1328】Radar Installation (贪心)
Radar Installation 原文是English,直接上中文 Descriptions: 假定海岸线是无限长的直线.陆地位于海岸线的一侧,海洋位于另一侧.每个小岛是位于海洋中的一个点.对于任 ...
- poj 1328 Radar Installation(nyoj 287 Radar):贪心
点击打开链接 Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43490 Accep ...
随机推荐
- Luogu P1073 最优贸易【最短路/建反图】 By cellur925
题目传送门 这么经典的题目,还是看了lyd的题解....唉难过. 一句话题意:在一张点有全都的图上找一条从1到n的路径,存在两个点p,q(p<q),使val[q]-val[p]最大. 给出的图是 ...
- Noip2014生活大爆炸版石头剪刀布【水模拟】
模拟暴力也要优雅. https://www.luogu.org/problemnew/show/P1328 像我这种蒟蒻就会敲无数个ifelse qaq. 可以优雅地进行预处理一下. 膜法真是好东西q ...
- 倒排索引构建算法BSBI和SPIMI
参考:https://blog.csdn.net/androidlushangderen/article/details/44889677 倒排索引 : 一般的索引检索信息的方式.比如原始的数据源假设 ...
- javascript匿名方法
首先,看一段很有意思的代码: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> < ...
- 【原创】《从0开始学RocketMQ》—单机搭建
内容目录 1. RocketMQ是什么? 2. 下载并解压 3. 启动NameServer 4. 启动 Broker 5. 关闭消息队列 1. RocketMQ是什么? RocketMQ是一种消息队列 ...
- Microsoft函数调用约定
Microsoft函数调用约定 对于所有调用共有的约定:ebx.ebp.esi.edi都是calle-save,即由被调用的函数负责它们的保存(如果被调用函数用到了这些寄存器的话) 先看函数调用发生了 ...
- [POI2012]Vouchers
Description 考虑正整数集合,现在有n组人依次来取数,假设第i组来了x人,他们每个取的数一定是x的倍数,并且是还剩下的最小的x个. 正整数中有m个数被标成了幸运数,问有哪些人取到了幸运数. ...
- openssh安装、设置指定端口号、免密码登录、变量传递、防暴力破解
首先确保机器挂在好光盘镜像,然后查看软件包信息 [root@xuegod63 ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev ...
- 如何成为一名优秀的 iOS 开发工程师
如果你是一位专业的iOS开发工程师,你应该为自己感到自豪.因为你能在强大的iOS系统下,一展身手实现自己和他人的想法,这是一件令人无比激动的事情. 作为一名iOS开发工程师,你一定想成为行业的佼佼者. ...
- "言官误国"
"言官误国" 之前读<明朝那些事儿>的时候,了解到了一个全新的概念,确切的说与之前的印象完全不符合的概念:言官.之前我印象中的言官都是魏征那样的人,为国为民.冒死直谏等 ...