题意:在坐标轴中给出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. if语句之有房么?有钱么?有能力么?

    思路:1.如果有房,可以谈谈 2.如果没有房,问第二个条件有钱么,如果有,可以谈谈 3.如果没有房没有钱,则问第三个条件有能力么,如果有,可以谈谈 4.如果以上三个条件都没有,则拜拜 Console. ...

  2. ios 调用webservice整理

    资料地址:http://blog.sina.com.cn/s/blog_a30ee5f701016yn3.html 学iphone开发有一段时间了,对于我这个新手来说,学习过程中,遇到不少问题,尤其是 ...

  3. iframe框架子页面与父页面间的通信

    需要注意的问题:页面最好放在服务器上测试避免跨域问题. 具体参考:http://www.cnblogs.com/ljhero/archive/2011/07/09/2101540.html

  4. Python 执行字符串表达式函数(eval exec execfile)

    eval:计算字符串中的表达式 exec:执行字符串中的语句 execfile:用来执行一个文件 在python 2中exec是语句,在python3中exec变为函数,后面要跟括号.在python3 ...

  5. Codeforces Round #254 (Div. 2) DZY Loves Chemistry【并查集基础】

    一开始不知道题意是啥意思,迟放进去反应和后放进去反应有什么区别 对于第三组数据不是很懂,为啥312,132的组合是不行的 后来发现这是一道考察并查集的题目 QAQ 怒贴代码: #include < ...

  6. 从java main方法说开去(转)

    刚刚接触java语言时,接触的便为一个java main方法.我们知道这样程序就可以运行了,但是程序是怎么运行起来的我们却不知道. 众所周知,当执行一个java程序时,首先会启动一个JVM虚拟机进程, ...

  7. Android Dialog详解

    前言          欢迎大家我分享和推荐好用的代码段~~ 声明          欢迎转载,但请保留文章原始出处:          CSDN:http://www.csdn.net        ...

  8. POJ1700(过河问题)

    #include<iostream> #include<algorithm> using namespace std; ]; int main() { int t,i; cin ...

  9. sourceinsight 相对路径设置

    1. mkdir sin(source insight prj dir) 2. creat sin prj 3. push OK directly without setting source fil ...

  10. 【转】CentOS上安装 jdk:rpm安装和源码安装

    1.安装 jdk-8u5-linux-x64.rpm 原文链接:http://www.cnblogs.com/xsi640/p/3756995.html 先下载最新的jdk版本 文件名:jdk-8u5 ...