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. 深入浅出MFC学习笔记 消息

    本章将会对MFC的消息映射和 命令传递机制做深入探讨. MFC规定了消息传递的路线,消息会按照这个路线传递下去,找不到归宿的话就交给DefWindowProc. 在产生窗口之前,如果我们在创建窗口时指 ...

  2. Svn使用遇到的错误

    1. 权限不足导致的错误

  3. Object-C 多线程中锁的使用-NSLock

    在多线程的编程环境中,锁的使用必不可少! 于是,今天来总结一下为共享资源加锁的操作方法.   一.使用synchronized方式   //线程1 dispatch_async(dispatch_ge ...

  4. zufeoj 数值排序(简单题)

    数值排序 时间限制: 1 Sec  内存限制: 128 MB提交: 186  解决: 45[提交][状态][讨论版] 题目描述 输入一串数字,把这串数字中的‘0’都看成空格,那么就得到一行用空格分割的 ...

  5. Composer安装使用

    Composer 是 PHP5.3以上 的一个依赖管理工具.它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们. 1.下载 2.安装成功 3.配置地址 4.安装代码库 镜像 配置json

  6. python开发面向对象基础:组合&继承

    一,组合 组合指的是,在一个类中以另外一个类的对象作为数据属性,称为类的组合      人类装备了武器类就是组合 1.圆环,将圆类实例后传给圆环类 #!/usr/bin/env python #_*_ ...

  7. java实现递归(1)

    1.递归算法基本思路: Java递归算法是基于Java语言实现的递归算法.递归算法是一种直接或者间接调用自身函数或者方法的算法.递归算法实质是把问题分解成规模缩小的同类问题的子问题,然后递归调用方法表 ...

  8. day3心得

    1. 集合 主要作用: 去重 关系测试, 交集\差集\并集\反向(对称)差集 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 >>&g ...

  9. python----python使用mysql

    Python操作MySQL主要使用两种方式: 原生模块 pymsql ORM框架 SQLAchemy pymql pymsql是Python中操作MySQL的模块,在windows中的安装: pip ...

  10. GY89的使用

    GY89集成了三块不同的芯片,分别为:BMP180.L3GD20和LSM303DLH,作用分别是获取温度压强.三轴陀螺仪和加速度计的数据.以下通过把各个模块的数据输出到终端来测试GY89的功能. #i ...