poj 1328 Radar Installation【贪心区间选点】
Radar Installation
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other)
Total Submission(s) : 22 Accepted Submission(s) : 9
We use Cartesian coordinate system, defining the coasting is the x-axis. The sea side is above x-axis, and the land side below. Given the position of each island in the sea, and given the distance of the coverage of the radar installation, your task is to write a program to find the minimal number of radar installations to cover all the islands. Note that the position of an island is represented by its x-y coordinates.
Figure A Sample Input of Radar Installations
The input is terminated by a line containing pair of zeros
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define MAX 11000
struct node
{
double beg;
double end;
}s[MAX];
bool cmp(node a,node b)
{
return a.beg<b.end;
}
int main()
{
int i,j;
int island,r;
double a,b;
int k=0;
while(scanf("%d%d",&island,&r)&&island!=0&&r!=0)
{
int ok=0;
for(i=0;i<island;i++)
{
scanf("%lf%lf",&a,&b);
if(fabs(b)>r)
{
ok=1;
break;
}
s[i].beg=a-sqrt(r*r-b*b);//区间左端
s[i].end=a+sqrt(r*r-b*b);//区间右端
}
if(ok)
{
printf("-1\n");
continue;
}
sort(s,s+island,cmp);
int sum=0;
double ans=-11000.0;
for(i=0;i<island;i++)
{
if(ans<s[i].beg)
{
ans=s[i].end;
sum++;
}
}
printf("Case %d: ",++k);
printf("%d\n",sum);
}
return 0;
}
poj 1328 Radar Installation【贪心区间选点】的更多相关文章
- POJ - 1328 Radar Installation(贪心区间选点+小学平面几何)
Input The input consists of several test cases. The first line of each case contains two integers n ...
- POJ 1328 Radar Installation 贪心 A
POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...
- poj 1328 Radar Installation(贪心+快排)
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- POJ 1328 Radar Installation 贪心算法
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- poj 1328 Radar Installation(贪心)
题目:http://poj.org/problem?id=1328 题意:建立一个平面坐标,x轴上方是海洋,x轴下方是陆地.在海上有n个小岛,每个小岛看做一个点.然后在x轴上有雷达,雷达能覆盖的范 ...
- POJ 1328 Radar Installation 贪心 难度:1
http://poj.org/problem?id=1328 思路: 1.肯定y大于d的情况下答案为-1,其他时候必定有非负整数解 2.x,y同时考虑是较为麻烦的,想办法消掉y,用d^2-y^2获得圆 ...
- POJ 1328 Radar Installation 贪心题解
本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 ...
- POJ 1328 Radar Installation#贪心(坐标几何题)
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<algorithm> #include<cmath ...
- 贪心 POJ 1328 Radar Installation
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...
- POJ 1328 Radar Installation 【贪心 区间选点】
解题思路:给出n个岛屿,n个岛屿的坐标分别为(a1,b1),(a2,b2)-----(an,bn),雷达的覆盖半径为r 求所有的岛屿都被覆盖所需要的最少的雷达数目. 首先将岛屿坐标进行处理,因为雷达的 ...
随机推荐
- 类库探源——System.Type
一.MSDN 描述 Type 类:表示类型声明:类类型.接口类型.数组类型.值类型.枚举类型.类型参数.泛型类型定义.以及开放或封闭构造的泛型类型. 命名空间: System 程序集:mscorlib ...
- 通过html5的range属性动态改变图片的大小
range属性已经是很成熟的属性了,我们可以使用这个属性进行动态调整图片的宽度,其中原理在于通过不断获取range的值,并赋予给所需要的图片,进而达到动态改变图片的效果.下面贴出具体的代码,主要参照了 ...
- 使用JsPlumb绘制拓扑图的通用方法
转自:http://www.it165.net/pro/html/201311/7616.html 使用JsPlumb绘制拓扑图的通用方法 一. 实现目标 绘制拓扑图, 实际上是个数据结构和算法的问题 ...
- Express使用html模板
express默认使用jade模板,可以配置让其支持使用ejs或html模板. 1. 安装ejs 在项目根目录安装ejs. npm install ejs 2.引入ejs var ejs = requ ...
- WAMP(Windows+Apache+Mysql+PHP)环境搭建
学习PHP已经有一段时间,一直没有写过关于开发环境搭建的笔记,现在补上吧,因为安装配置的步骤记得不是很清楚,借鉴了一些别人的经验,总结如下: 首先去官方网站下载各个软件,下载需要的版本: Apache ...
- InstallShield:自己备份
LIST listData;//声明listData listData = ListCreate(STRINGLIST);//创建一个空的实际字符串或数字列表. //参数都是在上个界面中赋值,然后在下 ...
- Android Capability 细粒度的权限控制
1. 传统的UID/GID,权限颗粒度太大 2. Capability: 细粒度的权限控制 3. 进程的Capability 4. 文件的Capability 5. 进程的Capability Bou ...
- C# 仿迅雷风格选项卡
private void listView1_SelectedIndexChanged(object sender, EventArgs e) { listView1.FullRowSelect = ...
- LINUX防火墙firewall、iptables
(1) 重启后永久性生效: 开启: systemctl enable iptables.service'.ln -s '/usr/lib/systemd/system/iptables.service ...
- Socket理解
简介 本文主要介绍的socket编程的实现相关的内容: 理论 函数 socket 用来创建socket描述符,它唯一标识一个socket int socket(int domain, int type ...