Radar Installation
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 115873   Accepted: 25574

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

Source

分析:首先根据小岛的坐标计算出每座小岛对应海岸线上的范围。将每个小岛对应在海岸线上的范围进行排序,使得每个雷达范围的最小值进行递增。
对雷达范围进行贪心。。。
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=;
#define INf 0x3f3f3f3f
struct node{
double l,r;
}point[maxn]; bool cmp(const node &a,const node &b){
return a.l<b.l;
} int main(){
int n,d;
int case1=;
while(~scanf("%d%d",&n,&d)&&n){
int flag=;
for(int i=; i<n; i++ ){
int x,y;
cin>>x>>y;
if(y>d){
flag=;
// break;
}
double p=sqrt((double)(d*d)-y*y);
point[i].l=x-p;
point[i].r=x+p;
}
printf("Case %d: ",++case1);
if(flag){
cout<<-<<endl;
continue;
}
sort(point,point+n,cmp);
int ans=;
node tmp=point[];
for( int i=; i<n; i++ ){
if(tmp.r>=point[i].r) tmp=point[i];
else if(tmp.r<point[i].l){
ans++;
tmp=point[i];
}
}
cout<<ans<<endl;
}
return ;
}

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. Radar Installation(贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 56826   Accepted: 12 ...

  3. Radar Installation 贪心

    Language: Default Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42 ...

  4. Radar Installation(贪心,可以转化为今年暑假不ac类型)

    Radar Installation Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) ...

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

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

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

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

  7. POJ 1328 Radar Installation 贪心算法

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

  8. POJ1328 Radar Installation(贪心)

    题目链接. 题意: 给定一坐标系,要求将所有 x轴 上面的所有点,用圆心在 x轴, 半径为 d 的圆盖住.求最少使用圆的数量. 分析: 贪心. 首先把所有点 x 坐标排序, 对于每一个点,求出能够满足 ...

  9. poj1328 Radar Installation —— 贪心

    题目链接:http://poj.org/problem?id=1328 题解:区间选点类的题目,求用最少的点以使得每个范围都有点存在.以每个点为圆心,r0为半径,作圆.在x轴上的弦即为雷达可放置的范围 ...

  10. POJ 1328 Radar Installation 贪心题解

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

随机推荐

  1. C#保存文件为无BOM的utf8格式

    如图所示,发现用C#的 File.WriteAllLines 方法,无论怎么设置,最终生成的文件都是 PC utf8,也就是CRLF,用SVN进行提交的时候,显示左侧为utf8,右侧为utf8 BOM ...

  2. 怎样让两个DIV在同一水平线上面显示

    css定义第二个div. float:right或者left. margin-top:0px 确保第二个DIV的宽度.如果宽度宽的话,会自动到下方的.

  3. linux-网站收藏

    创建sudo无密码登陆 http://www.aboutyun.com/blog-61-428.html

  4. numexpr low version warning

    runing https://colab.research.google.com/notebooks/mlcc/first_steps_with_tensor_flow.ipynb?hl=zh-cn# ...

  5. 【SQL 代码】SQL 语句记录(不定时更新)

    1.数值四舍五入,小数点后保留2位 round() 函数是四舍五入用,第一个参数是我们要被操作的数据,第二个参数是设置我们四舍五入之后小数点后显示几位. numeric 函数的2个参数,第一个表示数据 ...

  6. centos 中查找文件、目录、内容

    1.查找文件 find / -name 'filename'12.查找目录 find / -name 'path' -type d13.查找内容 find . | xargs grep -ri 'co ...

  7. 20151224今天发现到的两篇关于CSS架构、可复用可维护CSS和CSS学习提升能有改变思想观念意识的文章 分别是CSS架构目标和说说CSS学习中的瓶颈

    多讲一个,CSS全称是什么?CSS全称为Cascading Style Sheets,中文翻译为“层叠样式表”,简称CSS样式表又被我们称为CSS样式,CSS样式又被作为一种能制作出各种样式网页的技术 ...

  8. Java密码体系结构简介:Java Cryptography Architecture (JCA) Reference Guide

    来自Java官方的文档,作备忘使用. 简介: Java平台非常强调安全性,包括语言安全,密码学,公钥基础设施,认证,安全通信和访问控制. JCA是平台的一个主要部分,包含一个“提供者”体系结构和一组用 ...

  9. mycat偶尔会出现JVM报错double free or corruption并崩溃退出

    mycat偶尔会出现JVM报错double free or corruption并崩溃退出 没有复杂的sql,也没有大量的io INFO | jvm | // :: | *** Error in `j ...

  10. Mathematica绘制曲面交线方法(方法二)

    MeshFunction方式 Show[Graphics3D[{Opacity[0.5], Ball[{0, 0, 0}, 2]}], ParametricPlot3D[{4 + (3 + Cos[v ...