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的更多相关文章

  1. POJ1328Radar Installation(区间点覆盖问题)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 68597   Accepted: 15 ...

  2. poj1328Radar Installation 贪心

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64472   Accepted: 14 ...

  3. POJ1328Radar Installation(贪心)

    对于每一个点,可以找到他在x轴上的可行区域,这样的话就变为了对区间的贪心. #include<iostream> #include<stdio.h> #include<s ...

  4. 【贪心】POJ1328-Radar Installation

    [思路] 以每一座岛屿为圆心,雷达范围为半径作圆,记录下与x轴的左右交点.如果与x轴没交点,则直接退出输出“-1”.以左交点为关键字进行排序,从左到右进行贪心.容易知道,离每一个雷达最远的那一座岛与雷 ...

  5. Poj1328Radar Installation雷达安装

    原题链接 经典贪心,转化为问题为,对于所有的区间,求最小的点数能使每个区间都至少有一个点. #include<iostream> #include<cstdio> #inclu ...

  6. 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 ...

  7. Create an offline installation of Visual Studio 2017 RC

    Create an offline installation of Visual Studio 2017 RC ‎2016‎年‎12‎月‎7‎日                             ...

  8. An error occurred during the installation of assembly 'Microsoft.VC90.CRT……的问题

    有一段时间没有用到AnkhSvn了,今天工作需要安装了一下.结果安装到一半就无法继续了,提示An error occurred during the installation of assembly ...

  9. "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 ...

随机推荐

  1. IPv6协议介绍

    IPv6是为了解决基于IPv4的TCP/IP协议簇遇到的问题而推出的下一代IP协议.由于IPv4中采用的编制方式使得可用的网络地址和主机地址的数目远低于理论数目,随着全球互联网的快速发展,现有的IPv ...

  2. <hash命令:显示、添加或清除哈希表>

    linux系统下的hash指令: 说明:linux系统下会有一个hash表,当你刚开机时这个hash表为空,每当你执行过一条命令时,hash表会记录下这条命令的路径,就相当于缓存一样.第一次执行命令s ...

  3. 模拟抛硬币(C语言实现)

    实现代码: #include<stdio.h> #include<stdlib.h> int heads() { ; } int main(int argc, char *ar ...

  4. git管理和自动部署项目

    当一个项目需要纳入到版本控制的时候,选择的工具还是比较多的,最常见的就是工具有CVS,SVN,GIT等.在平时的开发中视情况而定,从来就没有最好的版本控制工具,只有最适合的工具.在这里我习惯用git来 ...

  5. 每日一“酷”之difflib

    介绍:difflib 比较序列.该模块包含一些用来计算和处理序列直接差异的工具.她对于比较文本尤其用,其中包含的函数可以使用多种常用差异格式生成报告. 测试数据(splitlines()按行划分为序列 ...

  6. 一段Android里面打印CallStatck的代码

    public void dumpCallStack() { java.util.Map<Thread, StackTraceElement[]> ts = Thread.getAllSta ...

  7. 【quartz】 数据库方式管理任务

    public static void Run(bool inClearJobs, bool inScheduleJobs) { var properties = new NameValueCollec ...

  8. zip压缩包密码破解

    有一种破解方法叫做Known plaintext attack.市面上的密码破解软件几乎都带有这个功能.操作方法就是找到加密压缩包中的任意一个文件,用同样的压缩软件同样的压缩方式压缩成一个不加密的包, ...

  9. 在Web API中使用Swagger-UI开源组件(一个深坑的解决)

    介绍: Swagger-Ui是一个非常棒的Web API说明帮助页,具体详情可自行Google和百度. 官网:http://swagger.io/    GitHub地址:https://github ...

  10. Java并发编程:Lock(上)

    在上一篇文章中我们讲到了如何使用关键字synchronized来实现同步访问.本文我们继续来探讨这个问题,从Java 5之后,在java.util.concurrent.locks包下提供了另外一种方 ...