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 ...
随机推荐
- CSS3选择器:nth-child和:nth-of-type之间的差异
CSS3选择器:nth-child和:nth-of-type之间的差异 这篇文章发布于 2011年06月21日,星期二,23:04,归类于 css相关. 阅读 57546 次, 今日 143 次 by ...
- ECSHOP订单自动确认
1.运行sql代码,生成数据库 CREATE TABLE `ecs_order_auto_confirm` ( `id` INT() UNSIGNED NOT NULL AUTO_INCREMENT, ...
- Linux系统下sendmail发送邮件失败的问题
问题是:安装完sendmail,启动服务后,发送邮件第一次发送成功,后面再次无论怎么发送都不行,换邮箱也不行.在确认我的邮件发送格式正确无误后,想到查看邮件发送日志: [root@backu ...
- Python标准库之urllib,urllib2自定义Opener
urllib2.urlopen()函数不支持验证.cookie或者其它HTTP高级功能.要支持这些功能,必须使用build_opener()函数创建自定义Opener对象. 1. build_open ...
- How to use the SQLIOSim utility to simulate SQL Server activity on a disk subsystem
SQLIOSim是模拟SQLServer的行为来测试IO性能,也可以对损坏磁盘进行一定校验 这是一个SQL Server 2012 安装完后自带的工具 一般在C:\Program Files\Micr ...
- MySQL 主键冲突,无法插入数据
数据库版本:5.6.16 问题:开发来电话说仓库无法下单,程序插入数据提示:入库单 xxxx1589762285确认失败:Duplicate entry '8388607' for key 'PRIM ...
- WPF-控件-ListView
<Window x:Class="DataTemplate2.MainWindow" xmlns="http://schemas.microsoft.com/win ...
- odp.net以及oracle oledb安装
连接Oracle数据库需要Oracle数据访问组件(ODAC). 1. 下载ODAC:http://www.oracle.com/technetwork/cn/database/windows/dow ...
- phpstrom 7.0 序列号
phpstrom 7.0 用户名 www.goipc.cn license key 13748-1204201000001dZdtN0KxZbl8zNH8RHFCz9t"gjKv9yXf2c ...
- NOSQL的应用,Redis/Mongo
NOSQL的应用,Redis/Mongo 1.心路历程 上年11月份来公司了,和另外一个同事一起,做了公司一个移动项目的微信公众号,然后为了推广微信公众号,策划那边需要我们做一些活动,包括抽奖,投票. ...