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

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<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
struct island
{
double x , y ;
double left , right ;
}a[];
int n ;
int d ;
bool cmp (island a , island b)
{
return a.x < b.x ;
} int main ()
{
// freopen ("a.txt" , "r" , stdin) ;
int cnt ;
int ans = ;
bool flag ; while (~ scanf ("%d%d" , &n , &d)) {
if (n == && d == )
break ;
flag = ; for (int i = ; i < n ; i++) {
scanf ("%lf%lf" , &a[i].x , &a[i].y) ;
if (a[i].y > 1.0 * d || a[i].y < || d <= ) {
flag = ;
}
if (!flag) {
a[i].left = (double) a[i].x - sqrt (1.0 * d * d - a[i].y * a[i].y) ;
a[i].right = (double) a[i].x + sqrt (1.0 * d * d - a[i].y * a[i].y) ;
}
}
if (flag) {
printf ("Case %d: -1\n" , ans++) ;
continue ;
}
sort (a , a + n , cmp) ;
cnt = ;
double l = a[].left , r = a[].right ;
for (int i = ; i < n ; i++) {
if (a[i].left > r) {
cnt++ ;
l = a[i].left ;
r = a[i].right ;
}
else {
l = a[i].left ;
r = a[i].right < r ? a[i].right : r ;
}
}
printf ("Case %d: %d\n" , ans++ , cnt) ;
}
return ;
}

别忘记每次都要跟新放radar的区间 ,orz

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 贪心

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

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

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

  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(贪心区间选点+小学平面几何)

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

  6. POJ 1328 Radar Installation 贪心算法

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

  7. POJ1328 Radar Installation(贪心)

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

  8. poj1328 Radar Installation —— 贪心

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

  9. POJ 1328 Radar Installation 贪心题解

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

随机推荐

  1. 记录毕业论文 LanguageTool 二次开发时用到的网站

    LanguageTool Development LanguageTool Supported Languages Share your knowledge about LT - LanguageTo ...

  2. idea 重写toString()模板,转成json格式

    idea toString()模板,将对象toString()为json格式. 1. 2.点击新增 public java.lang.String toString() { final java.la ...

  3. HoloLens开发手记 - Unity之语音输入

    对于HoloLens,语音输入是三大基本输入方式之一,广泛地运用在各种交互中.HoloLens上语音输入有三种形式,分别是: 语音命令 Voice Command 听写 Diction 语法识别 Gr ...

  4. 小白学习mysql之存储过程的优劣分析以及接入控制

    存储过程的优劣 存储过程是一组实现特定功能的SQL语句集合,存储过程一经编译便存储在了服务器上,可以通过调用存储过程的名字以及传入相应的参数来使用存储过程.要高层次的掌握存储过程,不能觉得依葫芦画瓢, ...

  5. sql server 使用函数辅助查询

    函数是所有语言系统下都具备的内部数据处理过程,SQL SERVER也同样内置了许多函数.在SQL SERVER中,函数是由一个或多个T-SQL语句组成的子程序.利用函数可以简化数据的处理操作. 函数分 ...

  6. 编写高质量代码改善C#程序的157个建议[C#闭包的陷阱、委托、事件、事件模型]

    前言 本文已更新至http://www.cnblogs.com/aehyok/p/3624579.html .本文主要学习记录以下内容: 建议38.小心闭包中的陷阱 建议39.了解委托的实质 建议40 ...

  7. C#中值类型和引用类型

    本文将介绍C#类型系统中的值类型和引用类型,以及两者之间的一些区别.同时,还会介绍一下装箱和拆箱操作. 值类型和引用类型 首先,我们看看在C#中哪些类型是值类型,哪些类型是引用类型. 值类型: 基础数 ...

  8. JSP/SERVLET入门教程--Servlet 使用入门

    现在的JSP书籍有的是直接讲述JSP的使用,然后再讲解SERVERLET的使用;也有书籍是先讲述SERVERLET的使用,然后讲解JSP使用.个人认为第二种相对好一些,至于原因大家可以在学习体会到!所 ...

  9. Sublime-jQueryDocs

    Package Control Messages======================== jQueryDocs---------- This package shows a selected ...

  10. iOS边练边学--NSURLSessionDataTask实现文件真正的断点续传

    实现重点: NSURLSessionDataTask要设置请求头,从路径中获取文件已经下载的长度(文件没有下载过的话,长度为0).通过这个长度设置请求的Range 如图: 接收到请求的时候key:文件 ...