题目地址:http://poj.org/problem?id=1328

 /*
贪心
(转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿,
这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知道,
问最少需要多少个雷达覆盖所有的岛屿。
(错误)思路:我开始是想从最左边的点雷达能探测的到的最右的位置出发,判断右边其余的点是否与该点距离小于d
是,岛屿数-1;不是,雷达数+1,继续。。。
(正确)思路:每个岛屿的座标已知,以雷达半径为半径画圆,与x轴有两个交点。
也就是说,若要覆盖该岛,雷达的位置范围是这两个交点。因此转化为覆盖区间的问题。
参考代码:http://www.cnblogs.com/kuangbin/archive/2011/07/30/2121838.html
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
using namespace std; const int MAXN = 1e3 + ;
const int INF = 0x3f3f3f3f;
struct NODE
{
int x, y;
double l, r;
}node[MAXN]; bool cmp(NODE a, NODE b)
{
return a.l < b.l;
} bool ok(int n, int d)
{
if (d < ) return false;
for (int i=; i<=n; ++i)
{
if (node[i].y > d) return false;
} return true;
} void work(int n, int d)
{
int cnt = ;
double now = node[].r;
for (int i=; i<=n; ++i)
{
if (now > node[i].r) now = node[i].r;
if (now < node[i].l)
{
now = node[i].r;
cnt++;
}
}
printf ("%d\n", cnt);
} int main(void) //POJ 1328 Radar Installation
{
//freopen ("I.in", "r", stdin); int n, d;
int cnt = ;
while (~scanf ("%d%d", &n, &d) && n && d)
{
for (int i=; i<=n; ++i)
{
scanf ("%d%d", &node[i].x, &node[i].y);
node[i].l = (double)node[i].x - sqrt ((double)d * d - node[i].y * node[i].y);
node[i].r = (double)node[i].x + sqrt ((double)d * d - node[i].y * node[i].y);
}
sort (node+, node++n, cmp);
printf ("Case %d: ", ++cnt);
if (!ok (n, d))
{
printf ("%d\n", -); continue;
}
work (n, d);
} return ;
} /*
void work(int n, int d)
{
int i = 1;
int j = 1;
int next = 1;
int num = 0;
int cnt = 0;
while (num < n)
{
double res = node[i].x + sqrt (d * d - node[i].y * node[i].y);
cnt++; num++;
int flag = 0;
fors (j=i+1; j<=n; ++j)
{
if (pow (node[j].x - res, 2) + pow (node[j].y, 2) <= d * d)
{
num++; next = j; flag = 1;
}
}
if (flag) i = next + 1;
else i++;
}
printf ("%d\n", cnt);
}
*/

贪心 POJ 1328 Radar Installation的更多相关文章

  1. POJ 1328 Radar Installation 贪心 A

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

  2. poj 1328 Radar Installation (简单的贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42925   Accepted: 94 ...

  3. poj 1328 Radar Installation(贪心)

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

  4. POJ 1328 Radar Installation 【贪心 区间选点】

    解题思路:给出n个岛屿,n个岛屿的坐标分别为(a1,b1),(a2,b2)-----(an,bn),雷达的覆盖半径为r 求所有的岛屿都被覆盖所需要的最少的雷达数目. 首先将岛屿坐标进行处理,因为雷达的 ...

  5. poj 1328 Radar Installation(nyoj 287 Radar):贪心

    点击打开链接 Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43490   Accep ...

  6. poj 1328 Radar Installation【贪心区间选点】

    Radar Installation Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) ...

  7. POJ 1328 Radar Installation【贪心】

    POJ 1328 题意: 将一条海岸线看成X轴,X轴上面是大海,海上有若干岛屿,给出雷达的覆盖半径和岛屿的位置,要求在海岸线上建雷达,在雷达能够覆盖全部岛屿情况下,求雷达的最少使用量. 分析: 贪心法 ...

  8. poj 1328 Radar Installation(贪心+快排)

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

  9. poj 1328 Radar Installation 排序贪心

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

随机推荐

  1. Linux 千万不要执行的10个命令

    1. rm -rf 命令 rm -rf命令是删除文件夹及其内容最快的方式之一.仅仅一丁点的敲错或无知都可能导致不可恢复的系统崩坏.下列是一些rm 命令的选项. rm 命令在Linux下通常用来删除文件 ...

  2. 解决android:theme="@android:style/Theme.NoDisplay" 加入这句话后程序不能运行

    原因: 原来用的是ActionBarActivity,继承自 ActionBarActivity的类必须指定固定的集中Theme风格,而这些 Theme 风格是需要导入V7中的 appcompat L ...

  3. 【转】INSTALL_FAILED_NO_MATCHING_ABIS 的解决办法

    在Android模拟器上安装apk的时候出现   INSTALL_FAILED_NO_MATCHING_ABIS 这个错误提示的解决办法. 是由于使用了native libraries .该nativ ...

  4. 一步步实现Nagios监控linux主机及飞信报警

    一步步实现Nagios监控linux主机及飞信报警 上篇文章介绍了在linux主机上架设nagios监控服务,并对windows主机进行服务状态变化的监控,这次我们继续上次内容.      首先实现n ...

  5. php获取网页内容方法总结

    抓取到的内容在通过正则表达式做一下过滤就得到了你想要的内容,至于如何用正则表达式过滤,在这里就不做介绍了,有兴趣的,以下就是几种常用的用php抓取网页中的内容的方法. 1.file_get_conte ...

  6. 【Python】Python XML 读写

    class ACTIVE_FILE_PROTECT_RULE_VIEW(APIView): renderer_classes = (JSONRenderer, BrowsableAPIRenderer ...

  7. 使用shadow dom封装web组件

    什么是shadow dom? 首先我们先来看看它长什么样子.在HTML5中,我们只用写如下简单的两行代码,就可以通过 <video> 标签来创建一个浏览器自带的视频播放器控件. <v ...

  8. C++ traits

    [本文链接] http://www.cnblogs.com/hellogiser/p/cplusplus-traits.html [分析] 什么是traits?其实它并不是一个新的概念,上个世纪90年 ...

  9. HDU1009老鼠的旅行 (贪心算法)

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  10. windows网络版象棋的实现

    要构建网络版象棋,首先应该创建服务器与客户端,建立socket连接 1) 开局,你是什么颜色 2)选择棋子, 3)走棋 4)悔棋(悔棋悔两步) 5)认输 网络实现: 1)建立连接 a.主机,建立监听s ...