fzuoj1111Radar Installation (贪心)
题目大意是在海岸线布置n个雷达,要求雷达的范围要包含所有的小岛;
思路:逆向思维把小岛看成一个个范围,与海岸线的交集,从最左端的开始找 (贪心最左端的点),接着不用一个一个去遍历,直接用前一个的右端点去替换下一个的左端点。。。。直至最后一个点。大致思想就是贪心,还是比较正常的题,适合刚学c语言的新生做(小白我就是一枚)。
下面是代码:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;
struct node
{
double left,right;
}island[];
bool cmp(node a,node b)
{
return a.left < b.left;
}
int main()
{
double x,y,d,temp;
int i,cnt,n,k=;
bool flag;
while(scanf("%d%lf",&n,&d)&&!(n==&&d==))
{
k++;
flag=false;
for(i=; i<n; i++)
{
scanf("%lf%lf",&x,&y);
if(y > d||d<)
{
flag = true;
}
island[i].right = x+sqrt(d*d-y*y);///岛屿右端点初始化
island[i].left = x-sqrt(d*d-y*y);///岛屿左端点初始化
}
if(flag)
{
printf("Case %d: -1\n",k);
continue;
}
sort(island,island+n,cmp);
temp=island[].right;
cnt=;
for(i=; i<n; i++)
{
if(island[i].right <= temp)
{
temp = island[i].right;///岛屿右端点的替换
}
else if(island[i].left > temp)
{
cnt++;
temp = island[i].right;
}
}
printf("Case %d: %d\n",k,cnt);
}
return ;
}
fzuoj1111Radar Installation (贪心)的更多相关文章
- POJ 1328 Radar Installation 贪心 A
POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...
- poj1328Radar Installation 贪心
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64472 Accepted: 14 ...
- Radar Installation(贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 56826 Accepted: 12 ...
- Radar Installation 贪心
Language: Default Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42 ...
- POJ1328 Radar Installation(贪心)
题目链接. 题意: 给定一坐标系,要求将所有 x轴 上面的所有点,用圆心在 x轴, 半径为 d 的圆盖住.求最少使用圆的数量. 分析: 贪心. 首先把所有点 x 坐标排序, 对于每一个点,求出能够满足 ...
- Radar Installation(贪心,可以转化为今年暑假不ac类型)
Radar Installation Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) ...
- 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(贪心区间选点+小学平面几何)
Input The input consists of several test cases. The first line of each case contains two integers n ...
- poj1328 Radar Installation —— 贪心
题目链接:http://poj.org/problem?id=1328 题解:区间选点类的题目,求用最少的点以使得每个范围都有点存在.以每个点为圆心,r0为半径,作圆.在x轴上的弦即为雷达可放置的范围 ...
随机推荐
- 在 Apache Ant中设置Proxy服务器
<target name="proxy"> <property name="proxy.host" value="https://m ...
- http缓存之304 last-modified,cache-control:max-age,Etag等
因最近客户端慢的问题,系统分析了下http协议缓存问题.本文主要记录总结http缓存相关知识. 1. 讨论涉及的要点 访问返回类 > 访问返回200 OK > 访问返回200 (from ...
- 1393: Robert Hood 旋转卡壳 凸包
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1393 http://poj.org/problem?id=2187 Beauty Contest ...
- Android JNI 本地开发接口
前言 我们为什么要用JNI --> 高效.扩展 高效:Native code效率高,数学运算,实时渲染的游戏上,音视频处理 (极品飞车,opengl,ffmpeg,文件压缩,图片处理-) 扩展: ...
- C# MVC jsonp初接触成功
利用jsonp进行跨域请求资源 C# MVC ApiControllers准备如下: 1.需要在引用处右键管理NuGet安装jsonp插件 2.在Application_Start()中配置 Glob ...
- 夺命雷公狗-----React---17--事件常用的属性
我们可以通过打印的方式将他打印出来看看,如下所示: <!DOCTYPE> <html> <head> <meta charset="utf-8&qu ...
- struts 文件下载
=============================struts 文件下载 ================================== 步骤一: JSP页面 <a href=& ...
- 8139too.c网卡驱动简单分析
从事linux C开发工作以来,工作内容主要是在应用层,对nginx和unbound等软件有些了解,也常对这2个软件进行二次开发. 对网络这块一直比较有兴趣.也很好奇网卡到底是怎么接受到报文的,以及报 ...
- 2013ACM/ICPC亚洲区南京站现场赛-HDU4809(树形DP)
为了这个题解第一次写东西..(我只是来膜拜爱看touhou的出题人的).. 首先以为对称性质..我们求出露琪诺的魔法值的期望就可以了..之后乘以3就是答案..(话说她那么笨..能算出来么..⑨⑨⑨⑨⑨ ...
- event.keyCode ,event.which ,event.charCode (2016-12-27 16:17:16)
javascript判断是否按回车键 <input id="chatMsg" name="chatMsg" type="text" s ...