POJ1328Radar Installation
http://poj.org/problem?id=1328
题的大意就是说在海里有小岛,坐标位置会给出,需要岸边的雷达覆盖所有的小岛,但雷达的覆盖范围有限,所以,需要最少的雷达覆盖所有的小岛,但若是有小岛没法被雷达给覆盖到,就输出-1;
这个题的话可以转化成区间问题就是看雷达的覆盖范围作为半径,A若是小岛的位置,根据雷达的覆盖范围只要不小于这个点的Y坐标,那个覆盖范围就是这个三角形的斜边,所以只要雷达位于1,2边上就可以覆盖到这个小岛
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std ;
struct node
{
double x,y;
} s[];
int cmp(struct node a,struct node b)
{
if(a.y< b.y)
return ;
else return ;
}
int main()
{
int n,d ;
int cnt = ;
while(cin>>n>>d)
{ int flag = ;
if(n == &&d == ) break ;
double a,b ;
for(int i = ; i <= n ; i++)
{
scanf("%lf %lf",&a,&b);
if(fabs(b) > d)
flag = ;
s[i].x = a-sqrt(d*d-b*b);
s[i].y = a+sqrt(d*d-b*b);
}
cout<<"Case"<<' '<<cnt<<':'<<' ';
if(flag == )
cout<<"-1"<<endl ;
else
{
sort(s+,s++n,cmp);
int sum = ;
double zhizhen = s[].y;
for(int i = ; i <= n ; i++)
{
if(s[i].x>zhizhen)
{
sum++;
zhizhen = s[i].y;
}
} cout<<sum<<endl;
}
cnt++;
}
return ;
}
POJ1328Radar Installation的更多相关文章
- POJ1328Radar Installation(区间点覆盖问题)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 68597 Accepted: 15 ...
- poj1328Radar Installation 贪心
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64472 Accepted: 14 ...
- POJ1328Radar Installation(贪心)
对于每一个点,可以找到他在x轴上的可行区域,这样的话就变为了对区间的贪心. #include<iostream> #include<stdio.h> #include<s ...
- 【贪心】POJ1328-Radar Installation
[思路] 以每一座岛屿为圆心,雷达范围为半径作圆,记录下与x轴的左右交点.如果与x轴没交点,则直接退出输出“-1”.以左交点为关键字进行排序,从左到右进行贪心.容易知道,离每一个雷达最远的那一座岛与雷 ...
- Poj1328Radar Installation雷达安装
原题链接 经典贪心,转化为问题为,对于所有的区间,求最小的点数能使每个区间都至少有一个点. #include<iostream> #include<cstdio> #inclu ...
- mysql-5.6.34 Installation from Source code
Took me a while to suffer from the first successful souce code installation of mysql-5.6.34. Just pu ...
- Create an offline installation of Visual Studio 2017 RC
Create an offline installation of Visual Studio 2017 RC 2016年12月7日 ...
- An error occurred during the installation of assembly 'Microsoft.VC90.CRT……的问题
有一段时间没有用到AnkhSvn了,今天工作需要安装了一下.结果安装到一半就无法继续了,提示An error occurred during the installation of assembly ...
- "Installation failed !" in GUI but not in CLI (/usr/bin/winusb: line 78: 18265 Terminated )
"Installation failed !" in GUI but not in CLI (/usr/bin/winusb: line 78: 18265 Terminated ...
随机推荐
- Linux美化——终端提示符
1. PS1变量简介[1] PS1是Linux终端用户的一个环境变量,用来说明命令行提示符的设置. 可以使用 man bash命令查看bash手册,找到该变量支持的特殊字符,以及这些特殊字符的意义: ...
- jquery的change 事件
jquery的change 事件 . <script src="jquery.min.js" type="text/javascript">< ...
- ADO.NET笔记——使用DataSet返回数据
相关知识: DataSet和DataAdapter的内部结构: DataSet通过DataAdapter从数据库中获取数据 DataSet对象内部包括一个集合(Tables),也就是可以拥有多个表(D ...
- Factory_Method
class Product { public: virtual ~Product() {} ; }; class ProductA : public Product { public: Product ...
- 关于iOS6应用中第三方类库不支持armv7s的问题解决
今天编译ios6+cocos2d v2 .1 beta2制作的游戏,出现下面的错误: ld: file is universal (3 slices) but does not contain a(n ...
- ref 和out的用法以及区别
在项目其实很少用ref和out,但是我们常用的工具resharep在帮我们重构的时候难免会给我们重构成带有ref或者是out的方法. 本人也是用的少所以难免忘记,留下简略笔记,以供后来自我参考: 为何 ...
- Golang学习笔记
一.基础 1. Hello World程序 demo: package main import "fmt" // 注释 //注释 func main() { fmt.Printf( ...
- ARPA
ARPA是英文Advanced Research Projects Agency的缩写,代表美国国防部高级研究计划署.是美国国防部高级研究计划管理局因军事目的而建立的,开始时只连接了4台主机,这便是只 ...
- Codeforces Round #331 (Div. 2) C. Wilbur and Points
C. Wilbur and Points time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 微软职位内部推荐-Senior SDE for Windows App Experience
微软近期Open的职位: Job posting title: Senior Software Development Engineer Location: China, Beijing Divisi ...