【思路】

以每一座岛屿为圆心,雷达范围为半径作圆,记录下与x轴的左右交点。如果与x轴没交点,则直接退出输出“-1”。以左交点为关键字进行排序,从左到右进行贪心。容易知道,离每一个雷达最远的那一座岛与雷达相距恰巧为半径的时候,可以得到最优解。假设上一个雷达与第before座岛相距为半径大小,对于当前的岛屿i:

如果before岛的右交点在i岛左交点的左侧,此时必然需要一个新的雷达,将当前before暂定为i,雷达数加一;

如果before岛的右交点在i岛右交点的右侧,为了让雷达举例尽可能地广,将雷达移至当前岛屿与x轴的交点上,将当前before暂定为i,雷达数不变。

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
double sqrt(double n);
struct rec
{
double left,right;
bool operator < (const rec& x) const
{
return left<x.left;
}
}; const int MAXN=+;
int n,d;
rec inter[MAXN]; int calculate()
{
sort(inter,inter+n);
int ans=;
int before=;
for (int i=;i<n;i++)
{
if (inter[before].right<inter[i].left)
{
ans++;
before=i;
}
else if (inter[before].right>=inter[i].right)
{
before=i;
}
}
return ans;
} int main()
{
int t=;
while (scanf("%d%d",&n,&d))
{
if (n==d && d==) break;
t++;
int f=;
for (int i=;i<n;i++)
{
double x,y;
cin>>x>>y;
if (d<y)
{
f=;
}
else
{
inter[i].left=x*1.0-sqrt(d*d-y*y);
inter[i].right=x*1.0+sqrt(d*d-y*y);
}
}
cout<<"Case "<<t<<": ";
if (f) cout<<calculate()<<endl;else cout<<-<<endl; }
return ;
}

【贪心】POJ1328-Radar Installation的更多相关文章

  1. [POJ1328]Radar Installation

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

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

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

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

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

  4. POJ1328——Radar Installation

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

  5. POJ1328 Radar Installation 解题报告

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

  6. 贪心——D - Radar Installation

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

  7. 贪心 + 计算几何 --- Radar Installation

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

  8. poj1328 Radar Installation(贪心 策略要选好)

    https://vjudge.net/problem/POJ-1328 贪心策略选错了恐怕就完了吧.. 一开始单纯地把island排序,然后想从左到右不断更新,其实这是错的...因为空中是个圆弧. 后 ...

  9. POJ1328 Radar Installation(贪心)

    题目链接. 题意: 给定一坐标系,要求将所有 x轴 上面的所有点,用圆心在 x轴, 半径为 d 的圆盖住.求最少使用圆的数量. 分析: 贪心. 首先把所有点 x 坐标排序, 对于每一个点,求出能够满足 ...

  10. zoj1360/poj1328 Radar Installation(贪心)

    对每个岛屿,能覆盖它的雷达位于线段[x-sqrt(d*d-y*y),x+sqrt(d*d+y*y)],那么把每个岛屿对应的线段求出来后,其实就转化成了经典的贪心法案例:区间选点问题.数轴上有n个闭区间 ...

随机推荐

  1. I题 hdu 1234 开门人和关门人

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1234 开门人和关门人 Time Limit: 2000/1000 MS (Java/Others)   ...

  2. JavaWeb使用Session防止表单重复提交

    在平时开发中,如果网速比较慢的情况下,用户提交表单后,发现服务器半天都没有响应,那么用户可能会以为是自己没有提交表单,就会再点击提交按钮重复提交表单,我们在开发中必须防止表单重复提交. 1.什么是表单 ...

  3. LeetCode 19 Valid Parentheses

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...

  4. [Leetcode Week15] Add Two Numbers

    Add Two Numbers 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/add-two-numbers/description/ Descrip ...

  5. 通过编译函数库来学习GCC【转】

    转自:http://blog.csdn.net/u012365926/article/details/51446295 基本概念 什么是库 在windows平台和linux平台下都大量存在着库. 本质 ...

  6. io多路复用-select()

    参照<Unix网络编程>相关章节内容,实现了一个简单的单线程IO多路复用服务器与客户端. 普通迭代服务器,由于执行recvfrom则会发生阻塞,直到客户端发送数据并正确接收后才能够返回,一 ...

  7. python 学习笔记 sqlalchemy

    数据库表是一个二维表,包含多行多列.把一个表的内容用Python的数据结构表示出来的话,可以用一个list表示多行,list的每一个元素是tuple,表示一行记录,比如,包含id和name的user表 ...

  8. 【Android XML】Android XML 转 Java Code 系列之 style(3)

    最近一个月把代码重构了一遍, 感觉舒服多了, 但总体开发进度没有变化.. 今天聊聊把style属性转换成Java代码的办法 先说结论: 引用系统style是无法完美的实现的, 我们如果有写成Java代 ...

  9. api文档工具

    平台选型         Apidoc         文档参考:http://apidocjs.com        优点      文档齐全,操作简单,ui清晰,代码注解查询性强,语言支持多元化, ...

  10. 过渡&动画

    进入/离开&列表过渡 概述 Vue在插入,更新或者移除Dom时,提供多种不同方式的应用过渡效果.包括以下工具 在css过渡和动画中自动应用class 可以配合使用第三方css动画库,如Anim ...