题意:在坐标轴中给出n个岛屿的坐标,以及雷达的扫描距离,要求在y=0线上放尽量少的雷达能够覆盖全部岛屿。

很明显的区间选点问题。

代码:

/*
* Author: illuz <iilluzen[at]gmail.com>
* Blog: http://blog.csdn.net/hcbbt
* File: l2911.cpp
* Create Date: 2013-09-09 20:51:05
* Descripton:
*/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std; const int MAXN = 1010;
int n, r, cas = 1; struct Point {
double lhs, rhs;
} a[MAXN]; bool cmp(Point a, Point b) {
if (a.rhs != b.rhs)
return a.rhs < b.rhs;
return a.lhs > b.lhs;
} int main() {
int x, y;
bool flag;
while (scanf("%d%d", &n, &r) && (n || r)) {
flag = true;
memset(a, 0, sizeof(a));
for (int i = 0; i < n; i++) {
scanf("%d%d", &x, &y);
if (flag) {
if (y > r) {
flag = false;
continue;
}
double t = sqrt((double)r * r - y * y);
a[i].lhs = x - t;
a[i].rhs = x + t;
}
}
printf("Case %d: ", cas++);
if (!flag)
printf("-1\n");
else {
sort(a, a + n, cmp);
// for (int i = 0; i < n; i++)
// printf("%lf %lf\n", a[i].lhs, a[i].rhs);
int ans = 1;
double start = a[0].rhs;
for (int i = 1; i < n; i++) {
if (a[i].lhs - start <= 1e-4)
continue;
ans++;
start = a[i].rhs;
}
printf("%d\n", ans);
}
}
return 0;
}

UVALive 2519 Radar Installation 雷达扫描 区间选点问题的更多相关文章

  1. UVAlive 2519 Radar Installation (区间选点问题)

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

  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【贪心 区间问题】

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

  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 【贪心】【区间选点问题】

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

  7. POJ1328 Radar Installation 【贪心&#183;区间选点】

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

  8. Radar Installation(POJ 1328 区间贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 68578   Accepted: 15 ...

  9. POJ 1328 Radar Installation(很新颖的贪心,区间贪心)

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

随机推荐

  1. redis研究记录

    1 redis安装 wget http://download.redis.io/redis-stable.tar.gz tar xvzf redis-stable.tar.gz cd redis-st ...

  2. Jquery中$.ajax()方法参数详解(转)

    转自:http://blog.sina.com.cn/doctor830619 url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数, ...

  3. javascript入门视频第一天 小案例制作 零基础开始学习javascript

    JavaScript 是我们网页设计师必备的技能之一.我们主要用javascript来写的是网页特效.我们从零基础开始学习javascript入门. 但是,好的同学刚开始不知道怎么学习,接触js,因此 ...

  4. A shallow summary of oracle log miner

    Sometimes, we should recover one or more rows data which is deleted carelessly by users, but it is n ...

  5. wget -r -nc -np "http://www.zhihu.com/"

    下载网站所有 -r,  --recursive          specify recursive download. -nc, --no-clobber              skip dow ...

  6. 进入MFC讲坛的前言(五)

    框窗.视图和文档及其关系 MFC架构的另外一个特色是它的框窗.视图和文档这个三位一体的结构,它是一个典型的MVC(Model.View and Controler)结构.严格的讲,框窗不属于MVC中的 ...

  7. android大牛高焕堂最新力作-android架构师之路

    android大牛高焕堂 个人介绍: Android专家顾问,台湾Android论坛主席,现任亚太地区Android技术大会主席,台湾Android领域框架开发联盟总架构师.发表100多篇Androi ...

  8. Bad Hair Day(单调栈 )

    Bad Hair Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15941   Accepted: 5382 Des ...

  9. signal()函数说明

    表头文件#include<signal.h> 功 能:设置某一信号的对应动作 函数原型:void (*signal(int signum,void(* handler)(int)))(in ...

  10. docker学习笔记5:利用commit命令创建镜像 和 删除本地镜像

    一.概述 创建镜像有两种方法,一是用commit命令,二是用dockerfile方法(这个更常用,在下面文章介绍).本章介绍commit方法. 在介绍commit命令前,我们先回顾下对代码的版本控制, ...