POJ1328-Radar Installation
描述:
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
The input consists of several test cases. The first line of each case contains two integers n (1<=n<=1000) and d, where n is the number of islands in the sea and d is the distance of coverage of the radar installation. This is followed 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
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.
代码:
每一个海岛可以在产生一个圆心的范围,在该范围内的任意雷达都可以覆盖到该点。要求雷达的最少的数目,采用贪心的思路,就是使选择的圆心能够尽量的属于更多的圆心的区间。如果雷达范围无法到达某个点,则无解。
边输入边处理的时候,不能break。就因为这个RE了无数次(╯‵□′)╯︵┴─┴
#include <cmath> #include <cstdlib> #include <iostream> using namespace std; typedef struct{double left;double right; }node; node a[1005]; int cmp(const void *a, const void *b){return (*(node*)a).left >= (*(node*)b).left ? 1 : -1; } int main(){int tc=1,n,d,flag,count,x,y;double delta,t;while( scanf("%d%d",&n,&d)!=EOF ){if( n==0 && d==0 ) break;flag=1;if( d<=0 ) flag=0;for( int i=0;i<n;i++ ){scanf("%d%d",&x,&y);if( y<=d ){//岛屿在雷达范围delta=sqrt((double)(d*d-y*y));a[i].left=x-delta;//得到区间a[i].right=x+delta;}else{flag=0;//这里不能写break,因为输入还未结束 }}if( flag==0 )//无解printf("Case %d: -1\n",tc);else{qsort(a,n,sizeof(node),cmp); t=a[0].right;count=1;for( int i=1;i<n;i++ ){if( a[i].left>t ){//当前区间左界大于相交区间的最右count++;t=a[i].right;//更新相交右界 }else{if( a[i].right<t )//取相交的区间t=a[i].right;//更新相交区间右界 }}printf("Case %d: %d\n",tc,count);}tc++;}system("pause");return 0; }
转载于:https://www.cnblogs.com/lucio_yz/p/4771828.html
POJ1328-Radar Installation相关推荐
- POJ-1328 Radar Installation 贪心
以每个点算出左右覆盖的雷达所在x轴范围,然后贪心计算出所需圆的个数. 当后一个点的圆心在x轴的左坐标在前一个点的右坐标的右坐标之前,则这个点就会被覆盖. 代码如下:(C++能过,G++ runtime ...
- 【贪心】Radar Installation(poj 1328)
Radar Installation poj 1328 题目大意: 在平面直角坐标系的一二象限上有n个小岛,现在让你在x坐标上布置雷达,每个雷达可以侦测以它为原心,半径为m的圆内的所有小岛,现在问侦测 ...
- 【POJ - 1328】Radar Installation(贪心+计算几何)安装雷达辐射岛屿
题干: Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the ot ...
- POJ Radar Installation 1328(雷达)贪心算法
问题描述 问题链接 Description Assume the coasting is an infinite straight line. Land is in one side of coast ...
- 【POJ1328】Radar Installation(贪心,决策包容)
problem 平面直角坐标系上有n个点. 在x轴上找尽量少的点,并以这些点为圆心画一个半径为d的圆,使得给定的点都在画出来的圆里. 求最少要画的点数,如果不能输出-1. solution 一.不能的 ...
- poj 1328 Radar Installation
题目链接:http://poj.org/problem?id=1328 题意: 设x轴为海岸,下方为陆地,上方为海.海上有n个岛屿,现在需要用雷达将所有的岛屿覆盖起来.给定岛屿个数及每个岛屿的坐标,给 ...
- Radar Installation(贪心,sort)
在poj上C++可以AC,但G++不行.杭电上更是好多的TLE,结果把cin改成scanf便可以轻松AC. #include <iostream> #include <algorit ...
- POJ - 1328 Radar Installation(贪心+思维)
题目链接:点击查看 题目大意:校长想通过监控设备覆盖学校内的N座建筑物,每座建筑物被视作一个质点,在笛卡尔坐标系中给出他们的坐标(x,y),并且所有建筑物均处在x轴的上方.因为学校的供电和传输线路均沿 ...
- Radar Installation
题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=27586 题意: 在海岸线上摆放雷达并限定雷达覆盖半径d,再以 ...
- POJ 1328 Radar Installation【贪心】
POJ 1328 题意: 将一条海岸线看成X轴,X轴上面是大海,海上有若干岛屿,给出雷达的覆盖半径和岛屿的位置,要求在海岸线上建雷达,在雷达能够覆盖全部岛屿情况下,求雷达的最少使用量. 分析: 贪心法 ...
最新文章
- python文件命名可以用中文吗-已经十多年了!你知道 Python 可以用中文命名变量吗?...
- 概率统计笔记:贝叶斯推断 Bayesian Inference
- 从0到1走进 Kaggle
- Android之Volley 源码解析
- 隐私泄漏在线检测源码
- Ionic常见问题--插件无法下载:npm ERR打包sha1错误
- ACM程序设计竞赛开幕式致辞
- 51单片机定时器实现钟表(LCD1602显示)
- Solaris11操作命令汇总
- SQL2008.AdventureWorks_All_datebases x86下载
- 计算机类中英附录,欧盟gmp附录1计算机系统(中英文对照).doc
- jmeter 中 Client implementation HttpClient4和java区别实践一
- 球体积公式计算4/3PIr*r*r,编写一个程序输入半径,求体积
- printJs 打印HTML 去掉页眉页脚
- [转载]班主任带着学生打副本 每周学习成绩就是DKP(这篇太雷人了,转载保持)...
- 关于多卡Android设备获取手机号的研究
- 微星主板开启安全启动以更新win11教程
- 转【JMeter】--JMeter下载及使用
- ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 D. 80 Days
- 计算机清理垃圾文件丢失怎么恢复,如何恢复windows电脑垃圾箱中清除的文件
热门文章
- 考研专业课计算机网络调剂,计算机网络信息中心2019年硕士研究生接收调剂信息公告...
- php mysql修改命令_PHP编程:mysql alter table命令修改表结构实例详解
- python 生成html表的报告_pytest文档7-pytest-html生成html报告
- python document_python 处理document文档 保留原样式
- 【科普】STP生成树协议
- 【科普】数据中心“容灾”和“备份”的区别
- mysql语句orderby_mysql中的orderby_MySQL
- 还在担心服务挂掉?Sentinel Go 让服务稳如磐石
- Serverless 与容器决战在即?有了弹性伸缩就不一样了
- redis取出list最边的一个_这几个Redis使用技巧,让你的程序快如闪电