Radar Installation
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 56702   Accepted: 12792

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
思路就是,排序之后,按右端点放雷达就好
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm> using namespace std; const int N=; struct node{
double l,r;
}seg[N]; int cmp(node a,node b){
return a.l<b.l;
} int main(){ //freopen("input.txt","r",stdin); int n,d,cases=;
while(~scanf("%d%d",&n,&d)){
if(n== && d==)
break;
int x,y;
double tmp;
int flag=;
for(int i=;i<n;i++){
scanf("%d%d",&x,&y);
tmp=sqrt((double)(d*d)-y*y);
seg[i].l=x-tmp;
seg[i].r=x+tmp;
if(y>d)
flag=;
}
sort(seg,seg+n,cmp);
printf("Case %d: ",++cases);
if(flag){
printf("-1\n");
continue;
}
int ans=;
node line=seg[];
for(int i=;i<n;i++){
if(line.r<seg[i].l){
ans++;
line=seg[i];
}
else if(line.r>=seg[i].r)
line=seg[i]; }
printf("%d\n",ans);
}
return ;
}
												

poj 1328 Radar Installation 排序贪心的更多相关文章

  1. poj 1328 Radar Installation(贪心)

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

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

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

  3. poj 1328 Radar Installation【贪心区间选点】

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

  4. POJ 1328 Radar Installation【贪心】

    POJ 1328 题意: 将一条海岸线看成X轴,X轴上面是大海,海上有若干岛屿,给出雷达的覆盖半径和岛屿的位置,要求在海岸线上建雷达,在雷达能够覆盖全部岛屿情况下,求雷达的最少使用量. 分析: 贪心法 ...

  5. poj 1328 Radar Installation 【贪心】【区间选点问题】

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

  6. POJ 1328 Radar Installation【贪心 区间问题】

    题目链接: http://poj.org/problem?id=1328 题意: 在x轴上有若干雷达,可以覆盖距离d以内的岛屿. 给定岛屿坐标,问至少需要多少个雷达才能将岛屿全部包含. 分析: 对于每 ...

  7. 贪心 POJ 1328 Radar Installation

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

  8. POJ 1328 Radar Installation 贪心 A

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

  9. poj 1328 Radar Installation (简单的贪心)

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

随机推荐

  1. SQL 存储过程分页

    CREATE PROC p_Team_GetTemaList @pageindex INT , @pagesize INT , @keywords VARCHAR(200) , --模糊查询 名称 标 ...

  2. 用Max导出Unity3D使用的FBX文件流程注解(转载)

    http://www.cnblogs.com/wantnon/p/4564522.html 从max导出FBX到Unity,以下环节需要特别注意.1,单位设置   很多人在建模,动画的时候,默认的ma ...

  3. CentOS7网卡改名

    # vi /etc/sysconfig/grub 修改上面内容中的GRUB_CMDLINE_LINUX的值,增加net.ifnames=0 biosdevname=0 执行:grub2-mkconfi ...

  4. Python模块:Random(未完待续)

    本文基于Python 3.6.5的官文random编写. random模块简介 random为各种数学分布算法(distributions)实现了伪随机数生成器. 对于整数,是从一个范围中均匀选择(u ...

  5. 创建第一个MySQL数据库earth及表area

    Windows 10家庭中文版,MySQL 5.7.20 for Win 64,2018-05-08 数据库earth描述: 用于记录地球上的事物,一期包含地理区域信息——表area. 字符集编码:u ...

  6. Densely Connected Convolutional Networks 论文阅读

    毕设终于告一段落,传统方法的视觉做得我整个人都很奔溃,终于结束,可以看些搁置很久的一些论文了,嘤嘤嘤 Densely Connected Convolutional Networks 其实很早就出来了 ...

  7. java基础28 单例集合Collection下的List和Set集合

    单例集合体系: ---------| collection  单例集合的根接口--------------| List  如果实现了list接口的集合类,具备的特点:有序,可重复       注:集合 ...

  8. win10 操作配置备忘

    让程序自动启动 如果想要实现应用程序在所有的用户登录系统后都能自动启动,就把该应用程序的快捷方式放到"系统启动文件夹"里: C:\ProgramData\Microsoft\Win ...

  9. 【转】Python验证码识别处理实例

    原文出处: 林炳文(@林炳文Evankaka) 一.准备工作与代码实例 1.PIL.pytesser.tesseract (1)安装PIL:下载地址:http://www.pythonware.com ...

  10. 学习Nodejs的第一步

    最近看了几本关于Node.js的书,本来个人技术分享网站http://yuanbo88.com/是打算用Node.js作为服务器端语言来处理后台的,后来又改成了PHP(也是自己研究,毕竟网上DEMO多 ...