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) ...
随机推荐
- ScrollView在调试状态一点击就挂的原因(OnMouseActivate)
这几天做的一个任务是做一个Dialog,需要在这个Dialog中添加一个自定义的CSrollvew类,但是遇到一个比较扯淡的问题,程序直接运行时可以的,调试状态下一点击CSrollview就挂了.而且 ...
- mongo3.4 配置文件 注意事项
给mongo配置文件坑了好久,今天终于解决了.写个博客,庆祝一下. mongo3.4 版本,我是用YAML格式的配置文件. 一开始,配置之后,启动服务的时候,老是提示:“unrecognized op ...
- 查看/进入mac根目录的方式
1.通过“前往文件夹”快捷键组合 (1)打开finder,点击上部菜单栏“前往”,然后“个人”,直接跳转. (2)快捷键组合:command + shift + G:注意:打开finder后,再快捷键 ...
- Android Studio 快捷键整理
Alt+回车 导入包,自动修正 Ctrl+N 查找类Ctrl+Shift+N 查找文件Ctrl+Alt+L 格式化代码Ctrl+Alt+O 优化导入的类和包Alt+Insert 生成代码(如ge ...
- docker和jenkins安装启动
docker安装Jenkins 1.安装Docker 1.1 yum 包更新到最新 sudo yum update 1.2 安装需要的软件包, yum-util 提供yum-config-manage ...
- Python 发送邮件、加密 day5
一.发送邮件import yagmail username = 'xxxxx@126.com'#发邮件人使用的邮箱 password = '123abc' #免费的邮箱,这里用授权码,一般自己公司的, ...
- pop的运用
pop():弹出列表最后一个元素 练习题: num_list = [12, 45, 34,13, 100, 24, 56, 74, 109] one_list = [] two_list = [] t ...
- [工具]iostat
本文主要分析了Linux的iostat命令的源码 iostat源码共563行,应该算是Linux系统命令代码比较少的了.源代码中主要涉及到如下几个Linux的内核文件: 1./proc/disksta ...
- webpack打包出错,通过babel将es6转es5的出错。
错误信息如下: 解决方法: 1,先安装babel-preset-es2015到项目中, cnpm install babel-preset-es2015 --save-dev2,在项目根目录中新建一个 ...
- 仿探探卡片滑动vue封装并发布到npm
项目初始化使用 webpack-simple 方式比较方便和容易配置,原来的方式各种坑慎入 vue init webpack-simple vue-card-slide cd vue-card-sli ...