Radar Installation
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 106491   Accepted: 23648

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轴为分界,y>0部分为海,y<0部分为陆地,给出一些岛屿坐标(在海中),再给出雷达可达到范围,雷达只可以安在陆地上,问最少多少雷达可以覆盖所以岛屿。 分析:
开始是这么想的:把二维抽象位1维的,只有x轴,因为岛屿都投影在x轴上,第一个雷达站在最左边是第一个岛屿,从头开始遍历这些岛屿,在第一个雷达站覆盖范围内的就
跳过,不在的就新建立一个雷达站,要求第二个雷达站的左边界刚好在没有覆盖的岛屿上(注意抽象为1维)
试了一下,wa了,这么做虽然可以减少雷达站的数量,但是肯定步数最优的 正确的做法:
对每个岛屿,要有雷达覆盖的话,那么其在x轴上面必须要有一共区间,雷达站必须在这个区间内才能覆盖该岛屿
求出每个岛屿的区间,如果有一些区间重叠的话,那么一共雷达站就能覆盖多个岛屿呀
将这些区间按照右边界大小排序(升序)
第一个雷达站放在第一个区间的右边界,如果第二个岛屿的左边界大于第一个岛屿的右边界,说明第一个雷达不能覆盖第二个岛屿,需要新建一个雷达站(在第二个岛屿的右边界)
如果第二个岛屿的左边界小于或者等于第一个岛屿的左边界的话,那么说明在第一个岛屿右边界建立的雷达站既能覆盖第一个岛屿也能覆盖第二个岛屿,所以跳过此岛屿,
下面依次类推

code:
#include<stdio.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <cstdlib>
#include <queue>
using namespace std;
#define max_v 1005
struct node
{
double x1,x2;
}p[max_v];
bool cmp(node a,node b)
{
return a.x2<b.x2;//岛屿右边界升序排序
}
int main()
{
int n,d,x,y;
int c=;
while(cin>>n>>d,n&&d)
{
int f=;
for(int i=;i<n;i++)
{
cin>>x>>y;
if(y>d)
f=;
double x1=x-sqrt(d*d*1.0-(y*y*1.0));
double x2=x+sqrt(d*d*1.0-(y*y*1.0));
p[i].x1=x1;
p[i].x2=x2;//得到岛屿左右边界
}
if(f==)
{
printf("Case %d: -1\n",c++);//存在岛屿到x的垂直距离大于雷达覆盖距离
continue;
}
sort(p,p+n,cmp);
int sum=;
int cur=;
for(int i=;i<n;i++)
{
if(p[i].x1>p[cur].x2)
{
cur=i;
sum++;
}
}
printf("Case %d: %d\n",c++,sum);
}
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

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

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

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

  4. poj 1328 Radar Installation(贪心)

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

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

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

  6. poj 1328 Radar Installation(nyoj 287 Radar):贪心

    点击打开链接 Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43490   Accep ...

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

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

  8. POJ 1328 Radar Installation【贪心】

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

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

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

随机推荐

  1. Effective C++ .37 virtual函数中默认参数的表现

    #include <iostream> #include <cstdlib> using namespace std; class Pen { public: ) { cout ...

  2. cf1043C. Smallest Word(贪心)

    题意 题目链接 Sol 这题打cf的时候真的是脑残,自己造了个abcdad的数据开心的玩了半天一脸懵逼...最后还好ycr大佬给了个思路不然就凉透了... 首先不难看出我们最后一定可以把字符串弄成\( ...

  3. python3在anaconda下安装caffe失败

    Python 跟 Python3 完全就是两种语言 0x00 import caffe FAILED 环境为 Ubuntu 16 cuda 8.0 NVIDIA 361.77 Anaconda2.昨天 ...

  4. js String字符串对象常见方法总结

    String对象常用来保存文本形式的数据. 其转化方法有二种: String(s) new String(s) String对象方法有: charAt() charCodeAt() concat() ...

  5. C# Winform中的ComboBox控件绑定数据库项目作为列表内容

    //初始化院区下拉列表,使用了Oracle数据库中的表项目 try { //string connString = "User=system;Password=manager;Data So ...

  6. geoserver 知识小计

    http://localhost:8888/geoserver/wms?service=WMS&request=GetCapabilities 这个地址用于获取发布的WMS服务的属性,用于获取 ...

  7. arcgis silverlight api 图层介绍

    Layer |--TiledMapServiceLayer | |--ArcGISTiledMapServiceLayer |--DynamicLayer | |--DynamicMapService ...

  8. javax.swing.JComponent 调用顺序

    网上截取的,感觉挺有用,记录下来. http://bbs.csdn.net/topics/310041707 java swing 感觉好复杂啊…………一点都不想用但是作业要用到 >_<; ...

  9. Build 2016: 发布明天的云创新来服务今天的开发者

    每个企业和行业都在被云潜移默化地改变着.随着云计算的速度.规模和灵活性的不断增加,云服务带来的可能性也在不断被拓展.想象一下,通过监测传感器,一位奶农能够将他的奶牛牛奶产量提高:或是一家医院能够自动监 ...

  10. Windows(7)上不能启动MySQL服务(位于本地计算机上)错误1067 :进程意外终止

    就这段时间,很多人在抱怨为什么自己的MySQL又打不开问题. 就“Windows(7)上不能启动MySQL服务(位于本地计算机上)错误1067 :进程意外终止”这个问题,我想到了几种方案解决: 一.首 ...