题目大意是在海岸线布置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 (贪心)的更多相关文章

  1. POJ 1328 Radar Installation 贪心 A

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

  2. poj1328Radar Installation 贪心

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64472   Accepted: 14 ...

  3. Radar Installation(贪心)

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

  4. Radar Installation 贪心

    Language: Default Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42 ...

  5. POJ1328 Radar Installation(贪心)

    题目链接. 题意: 给定一坐标系,要求将所有 x轴 上面的所有点,用圆心在 x轴, 半径为 d 的圆盖住.求最少使用圆的数量. 分析: 贪心. 首先把所有点 x 坐标排序, 对于每一个点,求出能够满足 ...

  6. Radar Installation(贪心,可以转化为今年暑假不ac类型)

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

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

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

  8. POJ - 1328 Radar Installation(贪心区间选点+小学平面几何)

    Input The input consists of several test cases. The first line of each case contains two integers n ...

  9. poj1328 Radar Installation —— 贪心

    题目链接:http://poj.org/problem?id=1328 题解:区间选点类的题目,求用最少的点以使得每个范围都有点存在.以每个点为圆心,r0为半径,作圆.在x轴上的弦即为雷达可放置的范围 ...

随机推荐

  1. ios - 谓词的使用

    谓词在搜索的时候非常管用.简单示例代码如下: 分类Person.h文件 #import <Foundation/Foundation.h> @interface Person : NSOb ...

  2. GPS部标平台的架构设计(九)-GPS监控客户端设计

    交通部的部标过检,所有的测试都是从客户端发起的,也是在客户端体现的,在客户端承载了部标标准所要求的所有的功能,是整个部标平台当中工作量最大的部分,也是最繁琐的部分. 客户端设计面临两个问题: 1.基于 ...

  3. OpenERP 使用与开发笔记(一)

    一直关注OpenERP,但一直未真正使用.最近一些数据想规范管理,免得使和EXCEL与WORD等到处找,所以想到OpenERP的自定义功能比较好,就再次找来相关资料重新拾掇起来.在这过程中,发现了许多 ...

  4. JAVA内存管理之堆内存和栈内存

    我们常常做的是将Java内存区域简单的划分为两种:堆内存和栈内存.这种划分比较粗粒度,这种划分是着眼于我们最关注的.与对象内存分配密切相关的两类内存域.其中栈内存指的是虚拟机栈,堆内存指的是java堆 ...

  5. Android系统调用

    android 中intent是经常要用到的.不管是页面牵转,还是传递数据,或是调用外部程序,系统功能都要用到intent. 在做了一些intent的例子之后,整理了一下intent,希望对大家有用. ...

  6. 利用selector设置ImageButton不同状态下的背景图片

    1.自定义MyButton类 public class MyButton extends Button { //This constructormust be public MyButton(Cont ...

  7. python学习笔记系列----(五)输入和输出

    这一章主要是讲述程序展示其数据的一些方法,一般都是直接按照一定的格式输出在屏幕,或者写入到文件以便以后使用.按照一定格式的输出,在python中实际就是对str的操作,主要就是介绍了formart() ...

  8. 在Excel里用vba给合并的单元格添加注释

    Excel里使用VBA对已经合并的单元格添加注释,直接使用AddComment会报: 运行时错误 '1004':应用程序定义或者对象定义错误 找了很多文章都没找到怎么解决,最后发现在AddCommen ...

  9. 简明外贸报价单(Price List)范本

    简明外贸报价单(Price List)范本 简明外贸报价单(Price List)范本 报价单 Price List 报价日期:年 月   日 Supplier Address 供应商 公司地址 Co ...

  10. angularjs的三目运算

    前言:前几天写代码的时候遇到一个问题,有一个按钮,有"已关注"和"+关注"两种状态,需要对这两种状态的按钮的背景颜色进行区分,单后点击"已关注&quo ...