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 题意:将一条海岸钱看为X轴,X轴的上方为大海,海上有许多岛屿,给出岛屿的位置与雷达的覆盖半径,要求在海岸线上建雷达,
   在雷达能够覆盖所有岛的基础上,求最少需要多少雷达。
 #include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdlib>
using namespace std;
#define MAX 1005
struct sea
{
double left;
double right;
} a[];
bool operator < (sea A,sea B)
{
return A.left<B.left;
}
int main()
{
int n,k=;
double d;
while(cin>>n>>d&&(n||d))
{
bool flag=false;
for(int i=; i<n; i++)
{
double x,y;
cin>>x>>y;
if(fabs(y)>d)
flag=true;
else
{ //计算区间
a[i].left=x*1.0-sqrt(d*d-y*y);
a[i].right=x*1.0+sqrt(d*d-y*y);
}
}
printf("Case %d: ",k++);
if(flag)
printf("-1\n");
else
{
int ans=; //雷达初始化
sort(a,a+n); // 排序
double s=a[].right;
for(int i=; i<n; i++)
{
if(a[i].left>s)
{
ans++; //雷达加一
s=a[i].right; // 更新右端点
}
else if(a[i].right<s)
s=a[i].right;
}
printf("%d\n",ans);
}
}
return ;
}

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(贪心区间选点+小学平面几何)

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

  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 贪心 难度:1

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

  5. poj 1328 Radar Installation(贪心)

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

  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 (简单的贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42925   Accepted: 94 ...

随机推荐

  1. Redis 中 redis.conf配置详细解析

    ########################################### 基本配置 ##################################### # 端口 port 666 ...

  2. CMake命令

    CMake手册详解,作者翻译的很详细,以下是自己进行的摘录: CMake80个命令(详细解释可以看here) CMD#1: add_custom_command为生成的构建系统添加一条自定义的构建规则 ...

  3. ubuntu关闭服务需要身份验证

    service tomcat stop ==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units === 需要通过认证才能停止“tom ...

  4. vue通过代理实现跨域

    http://www.cnblogs.com/wangyongcun/p/7665687.html

  5. Python中setup.py一些不为人知的技巧

    http://python.jobbole.com/80912/ 在我开始之前,我想先说清楚我将要解释的是些“窍门”.他们不是“最好的做法”,至少在一种情况下是不可取的. 说到不可取的做法,我会适时写 ...

  6. js 箭头函数

    箭头函数 ES6标准新增了一种新的函数:Arrow Function(箭头函数). x => x * x相当于: function (x) { return x * x; }箭头函数相当于匿名函 ...

  7. 6.26实力测试(小错笑cry)

    6.26测试 本次考试的粗心不忍吐槽(自带贴吧喷水表情),本次考试主要考察的知识点如下: 算法的分析与精简 暴力枚举输出字符 判断与枚举的综合考察 题目 第一题 [问题描述] 在一口井里,有一只神牛( ...

  8. sqli-labs:11-16,post注入

    sqli11: post:uname=xx' order by 2#&passwd=bla&submit=Submit(判定字段为2) 解释下为什么结果不是admin,这是sql执行的 ...

  9. c++11 多线程依次打印ABC

    并发 练习代码 #include <thread> #include <vector> #include <mutex> #include <iostream ...

  10. 博客写作的Checklist

    Checklist 1.不要发明术语. 2.不要使用指代不清的代词.如:我,他. 3.不要使用错误的承前省. 4.不要使用口语. 5.给出结论之前,先交代背景. 6.站立会议报告中应有燃尽图. 7.燃 ...