poj1328贪心 雷达,陆地,岛屿问题
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 60381 | Accepted: 13610 |
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
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
Output
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
Source
雷达的覆盖范围是一个以R为半径的圆,请用最少的雷达覆盖所有的小岛;当无法覆盖时 输出-1
思路:算出 每个小岛能被覆盖的雷达的圆心,即以小岛为圆心 R为半径 作圆,该圆与X轴的交点:
左交点为x-sqrt(R*R-y*y); 右交点为x+sqrt(R*R-y*y);
按照 左交点 排序,如果i点的左交点在 当前雷达的右边 则需安装一个新雷达,更新雷达
否则 如果 i点的右交点也在当前雷达的左边 则把当前雷达的圆心更新为该点的右交点;
代码
::
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
struct node{
double x;
double y;
}que[1005];
bool cmp(struct node a,struct node b){
return a.x<b.x;
}
int main(){
int n;
double d;
int count=0;
while(scanf("%d%lf",&n,&d)!=EOF){
int sum;
if(n==0&&d==0)
break;
int flag=0;
count++;
for(int i=0;i<n;i++){
double a,b;
scanf("%lf%lf",&a,&b);
que[i].x=a-sqrt(d*d-b*b);
que[i].y=a+sqrt(d*d-b*b);
if(b>d||d<=0||b<0)
flag=1;
}
if(!flag){
sort(que,que+n,cmp);
double temp;
temp=que[0].y;
sum=1;
for(int i=1;i<n;i++){
if(que[i].x>temp){
sum++;
temp=que[i].y;
}
else if(que[i].y<temp){
temp=que[i].y;
}
}
}
if(flag)
printf("Case %d: -1\n",count);
else
printf("Case %d: %d\n",count,sum);
}
return 0;
}
poj1328贪心 雷达,陆地,岛屿问题的更多相关文章
- POJ1328贪心放雷达
题意: 有一个二维坐标,y>0是海,y<=0是陆地,然后只能在y=0的岸边上放雷达,有n个城市需要被监控,问最少放多少个雷达. 思路: 贪心去做就行了,其实题目不 ...
- Poj1328 用雷达覆盖所有的岛屿
(此配图来自http://blog.csdn.net/zhengnanlee/article/details/9613161) 图中ABCD为海岛的位置.题目中会给出几个海岛的坐标位置,雷达覆盖半径d ...
- POJ1328贪心
题意:如今我们位于沿海地区,需要安装大炮,使得火力可以覆盖整个区域.海岸线可以视为是无限长的直线.陆地位于海岸线的一侧,海洋位于另一侧.海洋里有若干个岛屿,每个小岛可以视为海洋中的一个点.我们需要在海 ...
- poj1328 贪心
http://http://poj.org/problem?id=1328 神TM贪心. 不懂请自行搜博客. AC代码: #include<cstdio> #include<algo ...
- poj1328贪心中的区间问题
题意:给定海岛个数.雷达半径以及各海岛坐标,求能覆盖所有海岛的最小雷达数. 思路:先对每个海岛求一个区间:即能覆盖它的所有雷达的圆心所构成的区间.然后对区间排序,定义一个最右点over,依次延伸ove ...
- poj1328 Radar Installation(贪心 策略要选好)
https://vjudge.net/problem/POJ-1328 贪心策略选错了恐怕就完了吧.. 一开始单纯地把island排序,然后想从左到右不断更新,其实这是错的...因为空中是个圆弧. 后 ...
- UVAlive 2519 Radar Installation (区间选点问题)
Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. ...
- 翻译: 星球生成 II
翻译: 星球生成 II 本文翻译自Planet Generation - Part II 译者: FreeBlues 以下为译文: 概述 在前一章 我解释了如何为星球创建一个几何球体. 在本文中, 我 ...
- 雷达覆盖,贪心,类似活动安排(POJ1328)
题目链接:http://poj.org/problem?id=1328 解题报告: 1.按照头结点排序. #include <cstdio> #include <cmath> ...
随机推荐
- 【BZOJ1006】【HNOI2008】神奇的国度(弦图染色)
1006: [HNOI2008]神奇的国度 Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 1467 Solved: 603[Submit][Stat ...
- psd做成HTML相关参考页面
前端制作(美工)是怎么把PSD制作成页面的? 美工怎么做的我不清楚,因为我是做前端的,我就从前端这个角度说吧. 首先拿到PSD,先分析哪些是要导出为图片的,哪些是可以自己用代码完成的.将图片全部导出, ...
- wordpress中如何禁止或者屏蔽更新提示
WordPress禁止,插件更新,主题更新,wordpress本身更新提示的方法 禁止wp更新 : open file "wordpress\wp-includes\update.php&q ...
- 【BZOJ 1001】狼抓兔子 对偶图+SPFA
这道题是求图的最小割,也就是用最大流.但因为边太多,最大流算法会T,因此不能用最大流算法. 因为这是个平面图,所以求平面图的最小割可以使用特殊的技巧就是求对偶图然后求对偶图的最短路.把每个面看成一个点 ...
- SPOJ QTREE 树链剖分
树链剖分的第一题,易懂,注意这里是边. #include<queue> #include<stack> #include<cmath> #include<cs ...
- hdu4287 字典树
#include<stdio.h> #include<string.h> #include<stdlib.h> #define maxn 10 struct tri ...
- Ubuntu安装VMware Tools的方法
最后我将提供一个12版本的VMware Tools集合,包括了linux.iso. 背景: VMware Tools是VMware虚拟机中自带的一种增强工具,相当于VirtualBox中的增强功能(S ...
- USACO 3.2 ratios 高斯消元
题目原意很简单,就是解一个三元一次方程组 直接高斯消元解方程组,枚举最后一列的倍数(k) 注意double的精度,有很多细节需要处理 /* PROB:ratios LANG:C++ */ #inclu ...
- Bsoj 1322 第K小数
第K小数 Description 现在已有N个整数,你有以下三种操作: 1 A:表示加入一个值为A的整数: 2 B:表示删除其中值为B的整数: 3 K:表示输出这些整数中第K小的数: Input 第一 ...
- CSS3系列二(媒体支持、文字与字体相关样式、盒相关样式)
CSS3媒体支持 在css3中允许我们在不改变内容的情况下,在样式中选择一种页面的布局以精确的适应不同的设备,从而改善用户体验 可以利用meta标签在页面中指定浏览器在处理本页面时按照多少像素的窗口宽 ...