题目链接

题意:

给定一坐标系,要求将所有 x轴 上面的所有点,用圆心在 x轴, 半径为 d 的圆盖住。求最少使用圆的数量。

分析:

贪心。

首先把所有点 x 坐标排序, 对于每一个点,求出能够满足的 最靠右的圆心,即雷达的位置。

要保证雷达左面的点都被覆盖,如果不能覆盖就向左移,移到能将左边未覆盖的覆盖。如果后面的店不在雷达的覆盖区,则再加一雷达。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <cmath> using namespace std; const int maxn = + ; struct Pos{
double x, y;
bool operator < (const Pos &rhs) const {
return (x < rhs.x || (x == rhs.x && y > rhs.y));
}
}pos[maxn]; int main() {
int n1, n, d, kase = ;
bool flag;
while(scanf("%d %d", &n1, &d) == ) {
if(n1 == && d == ) break;
n = ;
flag = true;
for(int i=; i<n1; i++) {
cin >> pos[n].x >> pos[n].y;
if(pos[n].y > d) flag = false;
else n++;
} if(d <= ) flag = false; sort(pos, pos+n); int cnt = ;
double t, a, a1; a = pos[].x + sqrt(d*d - pos[].y*pos[].y); for(int i=; i<n && flag; i++) {
double x = pos[i].x, y = pos[i].y; t = d*d - y*y;
a1 = x + sqrt(t); if(x < a && a1 < a)
a = a1;
else if((x-a)*(x-a)+y*y > d*d) {
a = a1;
cnt++;
}
} printf("Case %d: ", ++kase);
if(!flag) printf("-1\n");
else printf("%d\n", cnt);
} return ;
}

POJ1328 Radar Installation(贪心)的更多相关文章

  1. poj1328 Radar Installation —— 贪心

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

  2. [POJ1328]Radar Installation

    [POJ1328]Radar Installation 试题描述 Assume the coasting is an infinite straight line. Land is in one si ...

  3. POJ--1328 Radar Installation(贪心 排序)

    题目:Radar Installation 对于x轴上方的每个建筑 可以计算出x轴上一段区间可以包含这个点 所以就转化成 有多少个区间可以涵盖这所有的点 排序之后贪心一下就ok 用cin 好像一直t看 ...

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

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

  5. POJ 1328 Radar Installation 贪心 A

    POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...

  6. POJ1328——Radar Installation

    Radar Installation Description Assume the coasting is an infinite straight line. Land is in one side ...

  7. POJ1328 Radar Installation 解题报告

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

  8. Radar Installation(贪心)

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

  9. Radar Installation 贪心

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

随机推荐

  1. Hadoop HDFS (3) JAVA訪问HDFS

    如今我们来深入了解一下Hadoop的FileSystem类. 这个类是用来跟Hadoop的文件系统进行交互的.尽管我们这里主要是针对HDFS.可是我们还是应该让我们的代码仅仅使用抽象类FileSyst ...

  2. STL——increment/decrement/dereference操作符

    increment/dereference操作符在迭代器的实现上占有非常重要的地位,因为任何一个迭代器都必须实现出前进(increment,operator++)和取值(dereference,ope ...

  3. 体验Impress.js

    用腻了ppt,prezi的风格看起来更酷一点儿,无意中得知有Impress.js这么一个H5版的prezi,nice,值得一试. 关于Impress.js,网上教程很多,但说实话就跟教小朋友一样,一步 ...

  4. Linux下/etc/fstab文件详解

    当系统启动的时候,系统会自动地从这个文件读取信息,并且会自动将此文件中指定的文件系统挂载到指定的目录. [root@rusky ~]# vi /etc/fstab # # /etc/fstab # C ...

  5. java.util 中的property

    学习中 两个博客: http://swiftlet.net/archives/1023 http://www.cnblogs.com/lingiu/p/3468464.html

  6. mysql 优化点小结

    1.数据库表设计的合理性 1)三范式 一范式:原子性,属性不可分: 二范式:无部分依赖, 例:(学号, 课程名称) → (姓名, 年龄, 成绩, 学分),存在部分依赖 (学号) → (姓名, 年龄) ...

  7. 新建android系统服务

    一.Android系统服务 Android提供了很多系统服务:如ActivityManger,PowerManger,WindowManger,WifiManger等等. 这些服务都是系统启动开始就一 ...

  8. iOS程序崩溃*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [37.5 nan]'

    今天上班打开昨天的程序运行,昨天跑的很溜的程序今天竟然crash了,好郁闷啊!下面附上crash的栈打印信息: 经过一番调试终于找到了原因,程序crash是因为CALayer的位置中含有不存在的数,就 ...

  9. [转]MySQL导入和导出SQL脚本

    首先,使用mysqldump命令的前提是,在Cmd中进入mysql安装目录下的bin目录下,才可以使用该命令.我的mysql安装在E:盘,所以,首先进入bin目录下:E:/Program Files/ ...

  10. SWT/RAP计算器

    /** *2.测试 */ public class NofTest extends AbstractEntryPoint {        Text text,text2;    RemoteObje ...