【思路】

以每一座岛屿为圆心,雷达范围为半径作圆,记录下与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. hdu 2059 龟兔赛跑(动态规划DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2059 龟兔赛跑 Time Limit: 1000/1000 MS (Java/Others)    M ...

  2. 用例图(Use Case Diagram)

    用例图(Use Case Diagram) 执行者/参与者(Actor): 表示与您的应用程序或系统进行交互的用户.组织或外部系统.用一个小人表示. 用例(Use Case): 即系统具有的功能,在用 ...

  3. FC4-i386-SRPMS

    [重点] http://archives.fedoraproject.org/pub/archive/fedora/linux/core/6/ http://archives.fedoraprojec ...

  4. jQuery为多个元素绑定同一个事件

    $('.toals,input[type=datetime]').on('focus',function(){ $('.footer-focus-none').css('display','none' ...

  5. 去掉a标签的虚线框,避免出现奇怪的选中区域

    a{blr:expression(this.onFocus=this.blur())}/*去掉a标签的虚线框,避免出现奇怪的选中区域*/

  6. jdbc预编译插入数据操作

    package com.test; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Prepare ...

  7. eetcode 之String to Integer (atoi)(28)

    字符串转为数字,细节题.要考虑空格.正负号,当转化的数字超过最大或最小是怎么办. int atoi(char *str) { int len = strlen(str); ; ; ; while (s ...

  8. POJ-3268

    Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13738   Accepted: 6195 ...

  9. SQl server 2008 附加数据库失败,错误:5120

    通过附加功能添加现成的数据库是非常方便的,然而有时会出现附加数据库失败.那么,我们该如何解决此问题? 有两种解决方法 [第一种方法] 第一步:找到要添加数据库的.mdf文件,点击右键,选择属性. 第二 ...

  10. AC日记——[POI2008]BLO-Blockade 洛谷 [POI2008]BLO-Blockade

    [POI2008]BLO-Blockade 思路: tarjan: 代码: #include <bits/stdc++.h> using namespace std; #define ma ...