poj 1328 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轴,X轴的上方为大海,海上有许多岛屿,给出岛屿的位置与雷达的覆盖半径,要求在海岸线上建雷达,
在雷达能够覆盖所有岛的基础上,求最少需要多少雷达。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdlib>
using namespace std;
#define MAX 1005
struct sea
{
double left;
double right;
} a[];
bool operator < (sea A,sea B)
{
return A.left<B.left;
}
int main()
{
int n,k=;
double d;
while(cin>>n>>d&&(n||d))
{
bool flag=false;
for(int i=; i<n; i++)
{
double x,y;
cin>>x>>y;
if(fabs(y)>d)
flag=true;
else
{ //计算区间
a[i].left=x*1.0-sqrt(d*d-y*y);
a[i].right=x*1.0+sqrt(d*d-y*y);
}
}
printf("Case %d: ",k++);
if(flag)
printf("-1\n");
else
{
int ans=; //雷达初始化
sort(a,a+n); // 排序
double s=a[].right;
for(int i=; i<n; i++)
{
if(a[i].left>s)
{
ans++; //雷达加一
s=a[i].right; // 更新右端点
}
else if(a[i].right<s)
s=a[i].right;
}
printf("%d\n",ans);
}
}
return ;
}
poj 1328 Radar Installation(贪心+快排)的更多相关文章
- POJ 1328 Radar Installation 贪心 A
POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...
- POJ - 1328 Radar Installation(贪心区间选点+小学平面几何)
Input The input consists of several test cases. The first line of each case contains two integers n ...
- 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 贪心 难度:1
http://poj.org/problem?id=1328 思路: 1.肯定y大于d的情况下答案为-1,其他时候必定有非负整数解 2.x,y同时考虑是较为麻烦的,想办法消掉y,用d^2-y^2获得圆 ...
- poj 1328 Radar Installation(贪心)
题目:http://poj.org/problem?id=1328 题意:建立一个平面坐标,x轴上方是海洋,x轴下方是陆地.在海上有n个小岛,每个小岛看做一个点.然后在x轴上有雷达,雷达能覆盖的范 ...
- POJ 1328 Radar Installation 贪心题解
本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 ...
- POJ 1328 Radar Installation#贪心(坐标几何题)
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<algorithm> #include<cmath ...
- 贪心 POJ 1328 Radar Installation
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...
- poj 1328 Radar Installation (简单的贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42925 Accepted: 94 ...
随机推荐
- 利用dom4j读写XML
public static HashMap<String, String> ReadConfig() { HashMap<String, String> map=new Has ...
- go流程控制与函数
package main; import ( "fmt" ); func main() { isRun := true; //条件判断 if isRun { fmt.Printf( ...
- [z]libevent入门教程:Echo Server based on libevent 不指定
[z]https://www.felix021.com/blog/read.php?2068 花了两天的时间在libevent上,想总结下,就以写简单tutorial的方式吧,貌似没有一篇简单的说明, ...
- tiny4412 启动方式
1.iROM(BL0):是指Exynos4412的iROM中固化的启动代码,其作用是初始化系统时钟,设置看门狗,初始化堆和栈,加载8kb的bl1到Exynos4412的一个64kb大小内部sram(I ...
- C语言中简单的for循环和浮点型变量
浮点型变量:常数中带有小数点的叫做浮点型 以下用for循环写一个摄氏度和华氏度的转换的C程序 [见 http://www.linuxidc.com/Linux/2013-08/88513.htm ] ...
- andorid 菜单 进度条
activity_ui2.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout x ...
- 关于出现“对不起,您安装的不是正版应用...”的解决方法
由于Discuz X版本增加了对插件的版本检测,在安装时,可能会出现:"对不起,您安装的不是正版应用,安装程序无法继续执行"的提示,如下图: 唱唱反调小编在此给大家分享解决方法: ...
- 基于centos6.5 hadoop 集群搭建
1.修改Linux主机名2.修改IP3.修改主机名和IP的映射关系 ######注意######如果你们公司是租用的服务器或是使用的云主机(如华为用主机.阿里云主机等) /etc/hosts里面要配置 ...
- 关于使用的xshll和xftp中乱码咋办?
1.Xshll中 2.Xftp中同理都是一样的设置
- Maven中maven-source-plugin,maven-javadoc-plugin插件的使用
摘要:今天领导说要把项目通过maven生产源码包和文档包并发布到自己的私服上,经过查看mavne官网发现有两个maven插件可以做到这些工作,一个是maven-source-plugin,另一个是ma ...