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. mysql链接出现10060

    http://www.cnblogs.com/meetrice/p/5309666.html 使用navicate链接 http://www.cnblogs.com/cxint/p/7454054.h ...

  2. php curl get post 方法的封装

    在开发的时候,需要请求别人的接口,那么就要用到curl了 由于很多地方都会用到,就封装了两个,以后应该都会用到 /* * @desc curl POST 方式请求接口 */ function post ...

  3. git的操作

    学习源头: https://www.cnblogs.com/yaoxc/p/3946280.html https://www.cnblogs.com/jeremylee/p/5715289.html ...

  4. linux启动自动挂载分区和/etc/fstab简单修复

    让后加的分区能够启动时自动挂载,需要把配置写入文件 /etc/fstab vi /etc/fstab UUID=3f5859e0-592f-42cd-b533-570422fb85be   / ext ...

  5. codeforces 985 D. Sand Fortress(二分+思维)

    Sand Fortress time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  6. PHP读取文件夹数据,并分页

    protected function read_all ($dir){ // 确保目录有权限进入 if(!is_dir($dir)) return false; $handle = opendir($ ...

  7. Linux学习笔记 -- 系统目录结构

    以root用户登录系统后,在当前命令窗口下输入命令: ls / 我们可以看到目录结构类似下图: 树状目录结构可以表示为: 解析: /bin:bin是Binary的缩写, 这个目录存放着最经常使用的命令 ...

  8. mybatis 学习一 建立maven项目

    一.直接建立Maven项目方法 1.建立Maven项目 接下来使用Eclipse的maven构建一个web项目,以构建SpringMVC项目为例: 1.1 选择建立Maven Project 选择Fi ...

  9. python实现文件加密

    前言: 想实现批量文件加密,可惜批量.展时没有思路 0x1 没有加密前的图片 加密后!!! !!!打不开了 0x02: 代码 import hashlib def get_sha1(f): xd=op ...

  10. Python 中的进程与 锁

    理论知识 操作系统背景知识 顾名思义,进程即正在执行的一个过程.进程是对正在运行程序的一个抽象. 进程的概念起源于操作系统,是操作系统最核心的概念,也是操作系统提供的最古老也是最重要的抽象概念之一.操 ...