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. windows下python3 使用cx_Oracle,xlrd插件进行excel数据清洗录入

    我们在做数据分析,清洗的过程中,很多时候会面对各种各样的数据源,要针对不同的数据源进行清洗,入库的工作.当然python这个语言,我比较喜欢,开发效率高,基本上怎么写都能运行,而且安装配置简单,基本上 ...

  2. [转]Zen Cart官网屏蔽中国用户访问的真正原因

    近需要到 zen cart 的官方网站查询一些资料,却发现无法访问!在网上搜索一番以后,原来如此. Zen Cart官网屏蔽中国用户访问的真正原因 作者:[鹏程万里] 日期:2011-03-26 准备 ...

  3. 最简单的TCP程序

    网络编程里面最简单的一个tcp程序,把一个文件从客户端上传到服务器端,上传成功后服务器端提示上传完成.代码不多,一个服务端和一个客户端. 服务端代码: import java.io.FileOutpu ...

  4. PostgreSQL Replication之第二章 理解PostgreSQL的事务日志(3)

    2.3 理解一致性和数据丢失 挖掘PostgreSQL事务日志而不考虑一致性是不可能的.在本章的第一部分,我们已经大体上解释了事务日志的基本思想.您已经知道,无需事先的日志改变的能力,使数据处于一种好 ...

  5. BZOJ 3786: 星系探索 欧拉游览树

    一个叫 Euler-Tour-Tree 的数据结构,说白了就是用 Splay_Tree 维护欧拉序 #include <cstring> #include <algorithm> ...

  6. ES6学习笔记(十五)Generator函数的异步应用

    1.传统方法 ES6 诞生以前,异步编程的方法,大概有下面四种. 回调函数 事件监听 发布/订阅 Promise 对象 Generator 函数将 JavaScript 异步编程带入了一个全新的阶段. ...

  7. CF GYM 100781A(菊花图+直径)

    题目大意 给出若干颗树用最少的边把它们连成一个无向连通图,同时使图的直径最小.输出最小直径. 题解 我们定义树的半径为(树的直径+1)/2.符合题意的连接方式为.所有树的“中点”连在直径最长的树的中点 ...

  8. C#-修改图书借阅管理系统-错误与SQL server 2008错误、复制数据库

    VS2012错误: *)不存在从对象类型 System.Object[] 到已知的托管提供程序本机类型的映射 public DataTable loadData2UserSearch(params o ...

  9. [JLOI2015]装备购买(线性基)

    [JLOI2015]装备购买 题目描述 脸哥最近在玩一款神奇的游戏,这个游戏里有 nn 件装备,每件装备有 \(m\) 个属性,用向量 \(\mathbf{z_i}\)=\((a_1, \ldots ...

  10. 【转】C# HttpWebRequest提交数据方式

    [转]C# HttpWebRequest提交数据方式 HttpWebRequest和HttpWebResponse类是用于发送和接收HTTP数据的最好选择.它们支持一系列有用的属性.这两个类位 于Sy ...