题意:给定海岛个数、雷达半径以及各海岛坐标,求能覆盖所有海岛的最小雷达数。

思路:先对每个海岛求一个区间:即能覆盖它的所有雷达的圆心所构成的区间。然后对区间排序,定义一个最右点over,依次延伸over,如果over不在某个区间内,那么消耗一颗雷达,over更新为该区间的最右端,否则end更新为起点在over内的所有区间的最小右端点。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
const int maxn=;
typedef struct P
{
double start,over;
}P;
P point[maxn];
bool cmp(P a,P b)
{
return a.start<b.start;
}
int main()
{
int n;
double r;
int cas=;
while(cin>>n>>r)
{
if(n==&&r==) break;
int res=;
for(int i=;i<n;i++)
{
double x,y;
cin>>x>>y;
if(res==-) continue;
if(y>r){
res=-;
continue;
}
double tt=sqrt(r*r-y*y);
point[i].start=x-tt;
point[i].over=x+tt;
}
if(res==-)
{
cout << "Case " << ++cas<< ": " << res << endl;
continue;
}
sort(point,point+n,cmp);
double mi=-0x3ffff;
for(int i=;i<n;i++)
{
if(mi<point[i].start){
res++;
mi=point[i].over;
}
else if(mi>point[i].over){
mi=point[i].over;
}
}
cout << "Case " << ++cas<< ": " << res << endl;
}
return ;
}

我的代码

poj1328贪心中的区间问题的更多相关文章

  1. lintcode: 二叉查找树中搜索区间

    题目 二叉查找树中搜索区间 给定两个值 k1 和 k2(k1 < k2)和一个二叉查找树的根节点.找到树中所有值在 k1 到 k2 范围内的节点.即打印所有x (k1 <= x <= ...

  2. 贪心问题:区间覆盖 NYOJ 喷水装置(二)

    喷水装置(二) 时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描述 有一块草坪,横向长w,纵向长为h,在它的橫向中心线上不同位置处装有n(n<=10000)个点状的喷水 ...

  3. POJ1328贪心

    题意:如今我们位于沿海地区,需要安装大炮,使得火力可以覆盖整个区域.海岸线可以视为是无限长的直线.陆地位于海岸线的一侧,海洋位于另一侧.海洋里有若干个岛屿,每个小岛可以视为海洋中的一个点.我们需要在海 ...

  4. Yii 框架中带有区间的搜索

  5. uva 10020 Minimal coverage 【贪心】+【区间全然覆盖】

    Minimal coverage The Problem Given several segments of line (int the X axis) with coordinates [Li,Ri ...

  6. UVALive 6911 Double Swords (Set,贪心,求区间交集)

    补:华中VJ这个题目很多标程都不能AC了,包括我下面原本AC了的代码,再交就WA掉了,感觉是样例有问题呢-- 首先左边的是必须要选的,然后右边的需要注意,有些区间是可以舍掉的.1.区间里有两个不同的A ...

  7. 贪心问题:区间覆盖 POJ 1328 Rader Installation

    题目:http://poj.org/problem?id=1328 题意:给定海岛个数,雷达半径,输入各个海岛坐标,求能覆盖所有海岛的最少雷达数 题解: 1. 贪心的区间覆盖问题,尽量让每个雷达覆盖更 ...

  8. POJ - 2376 Cleaning Shifts 贪心(最小区间覆盖)

    Cleaning Shifts Farmer John is assigning some of his N (1 <= N <= 25,000) cows to do some clea ...

  9. UVA-11134 Fabled Rooks 贪心问题(区间贪心)

    题目链接:https://cn.vjudge.net/problem/UVA-11134 题意 在 n*n 的棋盘上,放上 n 个车(ju).使得这 n 个车互相不攻击,即任意两个车不在同一行.同一列 ...

随机推荐

  1. 软件开发常用的linux命令心得(ubuntu为例)

    软件开发过程中难免要经常对主机进行配置或者部署等操作,想到一些就写一些了,以后再更新 解压命令: a.如果是tar文件,则直接用 “tar zxvf 文件名”: b.如果是zip文件,用 “unzip ...

  2. Hibernate 系列教程13-继承-鉴别器与内连接相结合

    Employee public class Employee { private Long id; private String name; HourlyEmployee public class H ...

  3. Math类的round方法小解

    在Math类中有三个关于“四舍五入”的静态方法(ceil,floor,round): ① Math.ceil(number) 向上取整,Math.ceil(11.2) 结果:12            ...

  4. jQuery Mobile 学习

    jQuery Mobile 学习系列 http://blog.csdn.net/bao990423420/article/details/13995021

  5. CodeForces#378--A, B , D--暴力出奇迹....

    A题 A. Grasshopper And the String time limit per test 1 second memory limit per test 256 megabytes in ...

  6. android 在代码中使用 #ffffff 模式 设置背景色

    differentsum.setBackgroundColor(Color.parseColor("#F3733F"));

  7. shortcut to open a linux terminal

    1) alt+ f2 2) input "gnome-terminal" 3) press "enter"

  8. 手写js代码(一)javascript数组循环遍历之forEach

    注:原文地址http://blog.csdn.net/oscar999/article/details/8671546 我这里是仿照学习! 1.js的数组循环遍历 ①数组的遍历首先想到的是for()循 ...

  9. Lorenzo Von Matterhorn

    Lorenzo Von Matterhorn Barney lives in NYC. NYC has infinite number of intersections numbered with p ...

  10. OpenGL学习--------颜色的选择

    OpenGL支持两种颜色模式:一种是RGBA,一种是颜色索引模式.无论哪种颜色模式,计算机都必须为每一个像素保存一些数据.不同的是,RGBA模式中,数据直接就代表了颜色:而颜色索引模式中,数据代表的是 ...