题目链接

题意:

给定一坐标系,要求将所有 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. oracle日期时间函数总结

    常常写 sql 的同学应该会接触到一些 oracle 的日期时间函数, 比如: 財务软件或者人力资源软件须要依照每年, 每季度, 每月, 甚至每一个星期来进行统计. 今天闲来没事, 特意从网上整理了一 ...

  2. TCP/IP之分层

    网络协议通常分不同层次进行开发,每一层分别负责不同的通信功能.一个协议族,比方T C P / I P,是一组不同层次上的多个协议的组合.T C P / I P通常被觉得是一个四层协议系统. 1.每层的 ...

  3. Android-Socket传输 GPRS网络

    手机使用GPRS网络与server进行Socket通信,代码下载地址:http://download.csdn.net/detail/wu20093346/7768481 用UDP协议与Socket调 ...

  4. [转] C++临时变量的生命周期

    http://www.cnblogs.com/catch/p/3251937.html C++中的临时变量指的是那些由编译器根据需要在栈上产生的,没有名字的变量. 主要的用途主要有两类: 1) 函数的 ...

  5. ViewPagerindicator 源码解析

        ViewPagerindicator 源码解析   1. 功能介绍 1.1 ViewPagerIndicator ViewPagerIndicator用于各种基于AndroidSupportL ...

  6. ASP.NET-FineUI开发实践-17

    我又不用FineUI开发,所以FineUI项目经验等于0,最近在忙别的,所以也没工夫研究.积累了论坛和群里的问题,写下来留个备份 1.在grid可编辑单元格中,如果需要在点击该单元格时,单元格中所有文 ...

  7. 阿里UX矢量图标库–最强大的矢量图标库(Icon font制作力荐工具)

    继前面介绍过ICON-FONT的制作后,找了几个ICON库都是国外的今天偶然发现阿里巴巴的图标矢量库,www.iconfont.cn用了之后感觉很强大,丰富的图标库(集合阿里妈妈&淘宝的图标库 ...

  8. MySQL数据库中,使用游标循环遍历

    /*对*dt库下的所有数据表删除docuemttype为空和documenttype为MD,PD,ET的数据:delete from 表名 where length(documenttype)< ...

  9. 带A圈的秘密

    真嗒安全策略的罗罗,,害的我和其他的不一样.

  10. Linux2.6的所有内核版本

    Index of /pub/linux/kernel/v2.6 Name Last modified Size Parent Directory - incr/ 03-Aug-2011 20:47 - ...