Radar Installation
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 64472   Accepted: 14497

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; struct node
{
double L,R;
} p[1005];
int cmp(node p1,node p2)
{
return p1.L<p2.L;
}
int main()
{
int n,d,num=0;
while(cin>>n>>d)
{
num++;
if(n==0&&d==0)
break;
int flag=1;
for(int i=0; i<n; i++)
{
int u,v;
cin>>u>>v;
if(flag==0)
continue;
if(d<v) //注意半径能够取负的,所以不能用d*d<v*v比較
{
flag=0;
}
else
{
p[i].L=(double)u-sqrt((double)(d*d-v*v));
p[i].R=(double)u+sqrt((double)(d*d-v*v));
}
}
if(flag==0)
{
printf("Case %d: -1\n",num);
continue;
} sort(p,p+n,cmp);
double x=p[0].R;
int sum=1;
for(int i=1; i<n; i++)
{
if(p[i].R<x)
{
x=p[i].R;
}
else if(x<p[i].L)
{
sum++;
x=p[i].R;
}
}
printf("Case %d: %d\n",num,sum);
}
} /*把每一个岛屿来当做雷达的圆心。半径为d,做圆。与x轴会产生两个焦点L和R,这就是一个区间;
首先就是要把全部的区间找出来。然后x轴从左往右按L排序,再然后就是所谓的贪心
把那些互相重叠的区间去掉即可了区间也就是雷达;*/ /*
3 -3
1 2
-3 2
2 1
Case ... -1;
*/
//按R进行从左到右排序
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm> using namespace std; struct node
{
double L,R;
} p[1001];
int cmp(node p1,node p2)
{
return p1.R<p2.R;
}
int main()
{
int n,d,num=0;
while(cin>>n>>d)
{
num++;
if(n==0&&d==0)
break;
int flag=0;
for(int i=0; i<n; i++)
{
int u,v;
cin>>u>>v;
if(d<v)
{
flag=1; }
else if(flag==0)
{
p[i].L=u-sqrt(d*d-v*v);
p[i].R=sqrt(d*d-v*v)+u;
}
}
if(flag)
{
printf("Case %d: -1\n",num);
continue;
} sort(p,p+n,cmp);
double xR=p[0].R;
double xL=p[0].L;
int sum=1;
for(int i=1; i<n; i++)
{
if(p[i].L<=xR)
{
}
else if(p[i].L>xR)
{
xR=p[i].R;
sum++;
}
}
printf("Case %d: %d\n",num,sum);
}
}

poj1328Radar Installation 贪心的更多相关文章

  1. POJ1328Radar Installation(贪心)

    对于每一个点,可以找到他在x轴上的可行区域,这样的话就变为了对区间的贪心. #include<iostream> #include<stdio.h> #include<s ...

  2. 【贪心】POJ1328-Radar Installation

    [思路] 以每一座岛屿为圆心,雷达范围为半径作圆,记录下与x轴的左右交点.如果与x轴没交点,则直接退出输出“-1”.以左交点为关键字进行排序,从左到右进行贪心.容易知道,离每一个雷达最远的那一座岛与雷 ...

  3. POJ1328Radar Installation(区间点覆盖问题)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 68597   Accepted: 15 ...

  4. POJ 1328 Radar Installation 贪心 A

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

  5. Radar Installation(贪心)

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

  6. Radar Installation 贪心

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

  7. POJ1328 Radar Installation(贪心)

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

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

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

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

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

随机推荐

  1. BZOJ 2115 DFS+高斯消元

    思路: 先搞出来所有的环的抑或值 随便求一条1~n的路径异或和 gauss消元找异或和最大 贪心取max即可 //By SiriusRen #include <cstdio> #inclu ...

  2. Oracle 流程控制语句

    分为选择语句循环语句两大类:一 选择语句1 if then ...end;set serveroutput on declare var_name1 varchar2(50):='East'; var ...

  3. UVa 1151 Buy or Build【最小生成树】

    题意:给出n个点的坐标,现在需要让这n个点连通,可以直接在点与点之间连边,花费为两点之间欧几里得距离的平方,也可以选购套餐,套餐中所含的点是相互连通的 问最少的花费 首先想kruskal算法中,被加入 ...

  4. ReactiveCocoa使用记录-网络登录事件

    对于一个应用来说,绝大部分的时间都是在等待某些事件的发生或响应某些状态的变化,比如用户的触摸事件.应用进入后台.网络请求成功刷新界面等等,而维护这些状态的变化,常常会使代码变得非常复杂,难以扩展.而 ...

  5. TF.LSTM实现

    感悟:耗时最多的就是数据格式整理,其本身并不复杂 NN-LSTM-NN-SOFTMAX 数据格式:batch_size =>批大小,n_steps=>要建立多少lstm 0.原始输入数据格 ...

  6. memset函数的用法

    重点需要注意一个细节:memset是以byte来填充的,也就是一个字节(8bit)一个单位来填充. 因此:如果int array[10]: memset(array, 1, 10):然后再把array ...

  7. 【Henu ACM Round#19 D】 Points on Line

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 考虑l..r这个区间. 且r是满足a[r]-a[l]<=d的最大的r 如果是第一个找到的区间,则直接累加C(r-l+1,3); ...

  8. Spring Cloud学习笔记【六】Hystrix 监控数据聚合 Turbine

    上一篇我们介绍了使用 Hystrix Dashboard 来展示 Hystrix 用于熔断的各项度量指标.通过 Hystrix Dashboard,我们可以方便的查看服务实例的综合情况,比如:服务调用 ...

  9. [Recompose] Configure Recompose to Build React Components from RxJS Streams

    Recompose provides helper functions to stream props using an Observable library of your choice into ...

  10. 如何下载最新版的 Adobe Flash Player

    如何下载最新版的 Adobe Flash Player 中国访客用代理访问下面的链接,否则会自动跳转到 https://www.flash.cn/ 当我们从 https://get.adobe.com ...