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. 深入浅出jsonp

    前言 第一次听说jsonp,其实早在2年之前.当时在做一个活动页面的抽奖模块,要从服务端get一个概率,当时什么都不懂,同事说用ajax,我就用ajax,同事说dataType改成jsonp,我就改成 ...

  2. 高版本jquery尤其是1.10.2的版本设置input radio设置值的最正确的姿势。

    $("input:radio[name="analyshowtype"]").attr("checked",false); $(" ...

  3. [BZOJ 2656][ZJOI2012]数列(递归+高精度)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2656 分析: 很容易想到递归分治,但遇到奇数时候f[i]=f[i/2]+f[i/2+1 ...

  4. 《TCP/IP详解卷1:协议》第5章 RARP:逆地址解析协议-读书笔记

    章节回顾: <TCP/IP详解卷1:协议>第1章 概述-读书笔记 <TCP/IP详解卷1:协议>第2章 链路层-读书笔记 <TCP/IP详解卷1:协议>第3章 IP ...

  5. java通过地址获取主机名

    关键代码: try { String str=Chat.getJt().getText().toString();//获取输入内容 String[] ipstr=str.split("[.] ...

  6. OC基础--成员变量的封装

    一.封装的作用: 1.重用 2.不必关心具体的实现 3.面向对象三大特征之一 4.具有安全性 二.OC中成员变量的命名规范以及注意事项 1.命名规范--.成员变量都以下划线“_”开头 1)为了跟get ...

  7. nginx配置反向代理示例

    环境: nginx1:192.168.68.41 tomcat1:192.168.68.43 tomcat2:192.168.68.45 nginx安装网上很多教程,我是用yum安装的. 配置ngin ...

  8. ASP.NET MVC3 局部页面@RENDERBODY @RENDERPAGE@RENDERSECTION使用方法详细说明

    转载自:http://blog.163.com/wenchangqing_live/blog/static/173722309201211299817278/ asp.net mvc3局部页面使用方法 ...

  9. Android中的Uri.parse()

    1,调web浏览器 Uri myBlogUri = Uri.parse("http://www.baidu.com"); returnIt = new Intent(Intent. ...

  10. 【BZOJ-1797】Mincut 最小割 最大流 + Tarjan + 缩点

    1797: [Ahoi2009]Mincut 最小割 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1685  Solved: 724[Submit] ...