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轴上的弦即为雷达可放置的范围 ...
随机推荐
- 总结ThinkPHP使用技巧经验分享(一)
约定:1.所有类库文件必须使用.class.php作为文件后缀,并且类名和文件名保持一致2.控制器的类名以Action为后 缀3.模型的类名以Model为后缀,类名第一个字母须大写4.数据库表名全部采 ...
- Java学习手记2——多线程
一.线程的概念 CPU执行程序,就好比一个人在干事情一样,同一个时间你只能做一件事情,但是这样的效率实在是太低了,在你用电脑的时候,听歌就不能浏览网页,看电影就不能下载视频,你想想是不是很蛋疼. 所以 ...
- Windows Phone 三、样式和资源
定义样式和引用资源 <Page.Resources> <!-- 向资源字典中添加一个键为ButtonBackground值为SolidColorBrush对象 --> < ...
- JQuery selector - not
<div class="table"> <div class="row header"></div> <div cla ...
- VB.NET中Form窗体运行时,按ESC退出全屏状态
1.在其KeyDown事件添加: If e.KeyValue = 27 Then Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable ...
- Jenkins Slave 通过JNLP 的方式 访问Master IP 总是127.0.0.1
解决办法,重启机器 可能是我以前用的jenkins url 是127.0.0.1 然后是缓存什么没有释放掉所致 <jnlp codebase="http://183.62.104.48 ...
- [WCF]DomainServices客户端操作异常处理
作为个人备忘,不做排版.此扩展函数用于DomainServices的Load及SubmitChanges时处理Error信息,包括验证消息.实体冲突. public static string ToE ...
- linux 下链接无线网络
无线网卡配置此页由Linux Wiki用户Chenxing于2008年11月27日 (星期四) 09:28的最后更改. 在1233456的工作基础上.本文介绍在Linux命令行界面中手动配置无线网卡的 ...
- winform、C# 自动更新
用IIS或者是Tomcat搭建一个Web服务器,因为没有涉及到动态页面,所以用什么服务器无所谓,网上有太多资料,这里不再赘述. 废话不多说,直接上代码. HttpHelper, 访问网页,下载文件等 ...
- Azure Web Site 之 利用Azure Web site 发布网站
由于经常混迹于MSDN Azure论坛,少不了和一些外国朋友打交道.有的时候觉得还是有一些东西可以写出来与外国友人们分享下的, 所以就用一个开源项目建了一个英文blog项目. 在发布的时候,首选的就是 ...