Input

The 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

For 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
题意:假定海岸线是无限长的直线。陆地位于海岸线的一侧,海洋位于另一侧。每个小岛是位于海洋中的一个点。对于任何一个雷达的安装 (均位于海岸线上),只能覆盖 d 距离,因此海洋中的小岛被雷达安装所覆盖的条件是两者间的距离不超过 d 。 
我们使用卡笛尔坐标系,将海岸线定义为 x 轴。海洋的一侧位于 x 轴上方,陆地的一侧位于下方。给定海洋中每个小岛的位置,并给定雷达安装的覆盖距离,您的任务是写一个程序,找出雷达安装的最少数量,使得所有的小岛都被覆盖。注意:小岛的位置以它的 x-y 坐标表示。 题解:这道题乍一看没有思路,但是如果不从雷达考虑,从小岛考虑,那么每个小岛都有一个对应的覆盖区间,只有区间内的点才能覆盖这个岛,所以问题变成了区间选点
只是要注意,精度是double的 代码:
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; struct node
{
double l,r;
} a[]; int x[],y[];
int n,d,cnt,t=; bool cmp(node a,node b)
{
return a.l<b.l;
} int main()
{
while(scanf("%d%d",&n,&d)!=EOF&&n)
{
t++;
int flag=;
cnt=;
if(d<=)
{
flag=;
}
for(int i=; i<=n; i++)
{
scanf("%d%d",&x[i],&y[i]);
if(y[i]>d||y[i]<)
{
flag=;
}
double dr=sqrt((double)d*d-y[i]*y[i]);
a[i].l=x[i]-dr;
a[i].r=x[i]+dr;
} if(flag==)
{
printf("Case %d: -1\n",t);
continue;
}
sort(a+,a+n+,cmp);
double lim=a[].r;
for(int i=; i<=n; i++)
{
if(a[i].l>lim)
{
lim=a[i].r;
cnt++;
}
else
{
if(a[i].r<lim)
{
lim=a[i].r;
}
}
}
printf("Case %d: %d\n",t,cnt);
} }


POJ - 1328 Radar Installation(贪心区间选点+小学平面几何)的更多相关文章

  1. POJ 1328 Radar Installation 贪心 A

    POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...

  2. poj 1328 Radar Installation(贪心+快排)

    Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...

  3. POJ 1328 Radar Installation 贪心算法

    Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...

  4. poj 1328 Radar Installation(贪心)

    题目:http://poj.org/problem?id=1328   题意:建立一个平面坐标,x轴上方是海洋,x轴下方是陆地.在海上有n个小岛,每个小岛看做一个点.然后在x轴上有雷达,雷达能覆盖的范 ...

  5. POJ 1328 Radar Installation 贪心 难度:1

    http://poj.org/problem?id=1328 思路: 1.肯定y大于d的情况下答案为-1,其他时候必定有非负整数解 2.x,y同时考虑是较为麻烦的,想办法消掉y,用d^2-y^2获得圆 ...

  6. POJ 1328 Radar Installation 贪心题解

    本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 ...

  7. POJ 1328 Radar Installation#贪心(坐标几何题)

    (- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<algorithm> #include<cmath ...

  8. 贪心 POJ 1328 Radar Installation

    题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...

  9. POJ 1328 Radar Installation 【贪心 区间选点】

    解题思路:给出n个岛屿,n个岛屿的坐标分别为(a1,b1),(a2,b2)-----(an,bn),雷达的覆盖半径为r 求所有的岛屿都被覆盖所需要的最少的雷达数目. 首先将岛屿坐标进行处理,因为雷达的 ...

随机推荐

  1. STM32从boot跳转到app失败

    现象:在每次boot执行完跳转到APP时,都会跑飞 原因:在boot中使用到了USART和TIM,boot执行完没有关闭总中断 方法:在boot执行完跳转之前关闭中断,__disable_irq() ...

  2. IPv6与IPv4最主要的不同

    IP第6个版本(IPv6),是互联网协议的新版本,设计为IP第4版本(IPv4,RFC-791)的继任.从IPv4升级到IPv6主要的改变有以下几类: 扩展地址容量 IPv6将IP地址的位址从32位提 ...

  3. Python学习笔记之os模块

    Python中的os提供了非常丰富的方法用来处理文件和目录,下面我们将详细的介绍os相关的一些方法和函数: os 路径相关的函数: 1.os.listdir(dirname):列出dirname目录下 ...

  4. ubuntu上安装Adminer

    Apache 安装 $ sudo apt-get install apache2 php 安装 $ sudo apt-get install php7.0 $ sudo apt-get install ...

  5. TI技术官方论坛

    https://e2echina.ti.com/question_answer/dsp_arm/c6000_dsp/f/32/t/172279

  6. 第三方引擎应用场景分析--Tokudb,infobright

    TokuDBTokuDB的特色:• Fractal Tree而不是B-Tree• 内部结点不仅有指向父子的指针还有Buffer区,数据写入先写buffer区,FIFO结构,写入只需要顺序添加到Buff ...

  7. nandflash裸机程序分析

    它包含7个文件: head.S init.c main.c Makefile nand.c nand.lds 我们之前的程序都是在nandflash的前4k放代码,上电后自动拷贝到SRAM中,之后将S ...

  8. Linux性能监测:内存篇

    在操作系统里,虚拟内存被分成页,在 x86 系统上每个页大小是 4KB.Linux 内核读写虚拟内存是以 “页” 为单位操作的,把内存转移到硬盘交换空间(SWAP)和从交换空间读取到内存的时候都是按页 ...

  9. Hadoop编码解码【压缩解压缩】机制详解(1)

    想想一下,当你需要处理500TB的数据的时候,你最先要做的是存储下来.你是选择源文件存储呢?还是处理压缩再存储?很显然,压缩编码处理是必须的.一段刚刚捕获的60分钟原始视屏可能达到2G,经过压缩处理可 ...

  10. sql合并列

    oralce写法: select WM_CONCAT(A.title) as citys from tmpcity A sql server写法: select stuff((select ','+A ...