题目: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. javascript 事件的学习

    1.事件绑定: addEventListener , removeEventListener.是dom2级别的事件绑定 attachEvent , detachEvent 是IE的事件绑定. 2. 事 ...

  2. PHP实现冒泡算法

    <?php //php函数:count($arr)返回array的数值总数. function bubble_sort($arr){ for ($i = 6;$i > 0;$i --){ ...

  3. 为 Web 设计师准备的 25+ 款扁平 UI 工具包

    Flat UI Kit by Riki Tanone (free) Flat UI Kit (PSD) by Devin Schulz (free) Eerste UI Kit (free) Metr ...

  4. Web开发——Http协议剖析

    Http,即超文本传输协议,是建立在TCP/IP协议的基础上.在Web开发的过程中,Http协议是十分重要的,浏览器与服务器之间的交互就是基于Http协议的.Http协议如果展开全面讲解会有很多内容, ...

  5. Linux ps同时查找多个进程

    1.显示当前所有进程 SDCxM-SDCAM-root-root> ps aux USER       PID %CPU %MEM    VSZ   RSS TTY      STAT STAR ...

  6. 九,WPF资源

    WPF资源的优点 WPF资源系统是一种保管一系列有用对象的简单方法,从而可以更容易地重用这些对象,它主要有以下优点: 高效,通过资源可以定义一个对象,并在标记中的多个地方重用,这会使代码变的更加精简, ...

  7. u3d 2d序列动画代码

    using UnityEngine; using System.Collections; public class AniSprite : MonoBehaviour { private float ...

  8. 【转】 设定linux 系统可用资源

    getrlimit和setrlimit函数  每个进程都有一组资源限制,其中某一些可以用getrlimit和setrlimit函数查询和更改. #include #include int getrli ...

  9. 2016 系统设计第一期 (档案一)MVC bootstrap model弹出窗

    局部代码: <!-- 按钮触发模态框 --> <div style=""> <button class="btn btn-primary&q ...

  10. Jar包下载

    到maven上面下载 http://mvnrepository.com/artifact/redis.clients/jedis/2.9.0 到jarfire去下载 http://cn.jarfire ...