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

 

题意:建立一个平面坐标,x轴上方是海洋,x轴下方是陆地。在海上有n个小岛,每个小岛看做一个点。然后在x轴上有雷达,雷达能覆盖的范围为d,问至少需要多少个雷达能监测到多有的小岛。

思路:从左到右把每个小岛的放置雷达的区间求出,按结束点排序,从左至右看,当发现下一个区间的起始点大于前面所有区间的最小结束点的时候,答案加一。

 #include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h> using namespace std;
struct node
{
double a,b;
}area[]; int cmp(const void *a,const void *b)
{
return (*(node *)a).b>(*(node *)b).b?:-;
} int main()
{
int n,i,sum,f,h=;
double x,y,d,e;
while(~scanf("%d%lf",&n,&d)&&(n!=||d!=))
{
f=; sum=;
for(i=; i<n; i++)
{
scanf("%lf%lf",&x,&y);
area[i].a=x-sqrt(d*d-y*y);
area[i].b=x+sqrt(d*d-y*y);
if(y<)
y=-y;
if(y>d)
f=;
} if(f)
printf("Case %d: -1\n",h); else
{
qsort(area,n,sizeof(area[]),cmp);
e=area[].b;
for(i=; i<n; i++)
{
if(area[i].a>e)
{
sum++;
e=area[i].b;
}
}
printf("Case %d: %d\n",h,sum);
}
h++;
}
return ;
}

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(贪心+快排)

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

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

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

  4. POJ 1328 Radar Installation 贪心算法

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

  5. POJ 1328 Radar Installation 贪心 难度:1

    http://poj.org/problem?id=1328 思路: 1.肯定y大于d的情况下答案为-1,其他时候必定有非负整数解 2.x,y同时考虑是较为麻烦的,想办法消掉y,用d^2-y^2获得圆 ...

  6. POJ 1328 Radar Installation 贪心题解

    本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 ...

  7. POJ 1328 Radar Installation#贪心(坐标几何题)

    (- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<algorithm> #include<cmath ...

  8. 贪心 POJ 1328 Radar Installation

    题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...

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

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

随机推荐

  1. Yii框架中集成phprpc、hprose

    在项目开发的过程中有时候会涉及到对外提供接口供第三方程序调用或者是不同程序间需要相互通信,那么最通用的做法是用传统的SOAP方式来实现,用XML的文档格式来作为传输载体.但是这种方式不灵活,支持的数据 ...

  2. win10 安装scrapy

    在win10的环境下安装scrapy,并不能直接按照官网的手册(http://doc.scrapy.org/en/1.0/intro/install.html)一次性安装成功,根据我自己的安装过程中遇 ...

  3. js 操作cookie

    jquery.cookie中的操作: jquery.cookie.js是一个基于jquery的插件,点击下载! 创建一个会话cookie: $.cookie(‘cookieName’,'cookieV ...

  4. Android中获取应用程序(包)的信息-----PackageManager的使用(一)

    本节内容是如何获取Android系统中应用程序的信息,主要包括packagename.label.icon.占用大小等.具体分为两个 部分,计划如下:  第一部分: 获取应用程序的packagenam ...

  5. butterknife7.0.1使用

    1.官网:http://jakewharton.github.io/butterknife/ Introduction Annotate fields with @Bind and a view ID ...

  6. Oracle监听器—动态注册

    注册就是将数据库作为一个服务注册到监听程序.客户端不需要知道数据库名和实例名,只需要知道该数据库对外提供的服务名就可以申请连接到数据库.这个服务名可能与实例名一样,也有可能不一样. 注册分: 1. 静 ...

  7. MySQL --log-slave-updates

     官方说明:--log-slave-updates Command-Line Format --log-slave-updates Option-File Format log-slave-updat ...

  8. crontab定时任务中文乱码问题

    手动执行都很正常的的脚本,添加到定时任务中日志文件全是乱码经过多方查证终于找到了原因! crontab启动的任务没有获取系统的环境变量,导致中文乱码解决办法:   在执行的脚步中添加编码方式或者添加对 ...

  9. python学习笔记10(函数一): 函数使用、调用、返回值

    一.函数的定义 在某些编程语言当中,函数声明和函数定义是区分开的(在这些编程语言当中函数声明和函数定义可以出现在不同的文件中,比如C语言),但是在Python中,函数声明和函数定义是视为一体的.在Py ...

  10. Xcode 向6.0以后版本添加iOS开发空白模板

    打开finder,找到应用程序,找到xcode 右键显示包内容.按照如下目录进行查找:Contents ▸ Developer ▸ Platforms ▸ iPhoneOS.platform ▸ De ...