Radar Installation
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 54798   Accepted: 12352

Description

Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d distance, so an island in the
sea can be covered by a radius installation, if the distance between them is at most d. 



We use Cartesian coordinate system, defining the coasting is the x-axis. The sea side is above x-axis, and the land side below. Given the position of each island in the sea, and given the distance of the coverage of the radar installation, your task is to write
a program to find the minimal number of radar installations to cover all the islands. Note that the position of an island is represented by its x-y coordinates. 

 

Figure A Sample Input of Radar Installations



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的圆,与x轴的相交,假设不相交那么肯定完不成任务,反之就转化成了区间选点问题。

代码:

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
#define M 1005 struct node {
double st, en;
}s[M]; int cmp(node a, node b){
if(a.en == b.en) return a.st > b.st;
return a.en<b.en;
} int main(){
int n, v = 1; double d;
while(scanf("%d%lf", &n, &d), n||d){
int i, j;
double a, b;
int flag = 0;
for(i = 0; i < n; i ++){
scanf("%lf%lf", &a, &b);
if(b>d) flag = 1;
if(flag == 0){
s[i].en = a+sqrt(d*d-b*b);
s[i].st = a-sqrt(d*d-b*b);
//printf("%lf %lf %d..\n", s[i].st, s[i].en, i);
}
// scanf("%lf%lf", &s[i].st, &s[i].en);
}
printf("Case %d: ", v++);
if(flag){
printf("-1\n"); continue;
}
sort(s, s+n, cmp);
int ans = 1;
double maxr = s[0].en;
i = 1, j = 0;
while(i < n){
if(s[i].st <= s[j].en){
//if(maxr < s[i].en) maxr = s[i].en;
++i;
}
else {
//if(j == i-1)
j = i;
++ans;
// maxr = s[i].en;
}
}
printf("%d\n", ans);
}
return 0;
}

poj 1328 Radar Installation 【贪心】【区间选点问题】的更多相关文章

  1. POJ - 1328 Radar Installation(贪心区间选点+小学平面几何)

    Input The input consists of several test cases. The first line of each case contains two integers n ...

  2. POJ 1328 Radar Installation 贪心 A

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

  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 贪心算法

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

  5. poj 1328 Radar Installation(贪心)

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

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

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

  7. POJ 1328 Radar Installation 贪心题解

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

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

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

  9. 贪心 POJ 1328 Radar Installation

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

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

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

随机推荐

  1. 文本文件txt生成excel

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

  2. 学习RMQ-ST表

    RMQ一般是一个二维数组,用$dp[i][j]$表示起点为i开始连续数$2^j$个元素其中的最值,由于对于一个闭区间有:$R-L+1=len$因此也可以用另外一种记法:闭区间为$[i,i+2^j-1] ...

  3. [SDOI2015][bzoj3994] 约数个数和 [莫比乌斯反演]

    题面: 传送门 思路: 首先,我们需要证明一个结论:d(i*j)等于sigma(gcd(x,y)==1),其中x为i的约数,y为j的约数 对于nm的每一个质因子pi分别考虑,设n = pi^ai + ...

  4. BZOJ1562 [NOI2009]变换序列 【KM算法】

    题目 输入格式 输出格式 输入样例 5 1 1 2 2 1 输出样例 1 2 4 0 3 提示 30%的数据中N≤50: 60%的数据中N≤500: 100%的数据中N≤10000. 题解 每个位置可 ...

  5. Python之面向对象:方法

    一.类的三种方法 1.实例方法 def func(self): 由对象调用:至少一个self参数:执行普通方法时,自动将调用该方法的对象赋值给self: 只能通过实例调用   2.静态方法 @stat ...

  6. mac python 安装参考

    首先需明确: Mac 电脑上自带有 python 查看默认的 python 版本,打开终端输入命令 python,即可看到如下内容: 我的系统版本OS X 10.13.2,自带的Python版本是2. ...

  7. Flex布局--必然的选择

    这篇文章是我在阮一峰老师的flex布局教程下,按照自己的理解重写写一遍,以便增强理解.如果你来到这里最好去看一下阮一峰大神的Flex布局教程 正式开始自己的. 说起布局方式,大家首先要了解css3有哪 ...

  8. C/C++学习路线

    随着互联网及互联网+深入蓬勃的发展,经过40余年的时间洗礼,C/C++俨然已成为一门贵族语言,出色的性能使之成为高级语言中的性能王者.而在今天,它又扮演着什么样重要的角色呢?请往下看: 后端服务器,移 ...

  9. 配置微信api调扫码功能

    var url = encodeURIComponent(location.href.split('#')[0]); $.get(iapi+'/htweb/wx/getJsSdkSign?url='+ ...

  10. PE笔记之NT头PE签名

    typedef struct _IMAGE_NT_HEADERS {       DWORD Signature;                     //PE头签名PE\0\0       IM ...