n sprinklers are installed in a horizontal strip of grass l meters long and w meters wide. Each sprinkler is installed at the horizontal center line of the strip. For each sprinkler we are given its position as the distance from the left end of the center line and its radius of operation. What is the minimum number of sprinklers to turn on in order to water the entire strip of grass?

Input

Input consists of a number of cases. The first line for each case contains integer numbers n, l and w with n ≤ 10000. The next n lines contain two integers giving the position of a sprinkler and its radius of operation. (The picture above illustrates the first case from the sample input.)

Output

For each test case output the minimum number of sprinklers needed to water the entire strip of grass. If it is impossible to water the entire strip output ‘-1’.

Sample Input

8 20 2

5 3

4 1

1 2

7 2

10 2

13 3

16 2

19 4

3 10 1

3 5

9 3

6 1

3 10 1

5 3

1 1

9 1

Sample Output

6

2

-1

题目链接 

题意

一块长l宽w的草坪,中心线有n个喷水装置,处于位置p,覆盖半径为r的区域。请选择尽量少的喷水装置,将整个草坪覆盖。

思路

考虑每个喷水器对草坪的实际影响,实质上是圆与草坪相交组成的矩形区间,那么这个问题就转换成了区间覆盖

先预处理,无法覆盖草坪的区间除去。小区间显然不应该考虑。初始起点为0,对于每个起点s,都取能覆盖它的最长的区间(按终点从大到小排序),并更新起点,循环这样的操作,直到覆盖了整个草坪。注意,这里需要double,r*r会爆int,实测。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include <queue>
#include <vector>
#include<bitset>
#include<map>
#include<deque>
using namespace std;
typedef long long LL;
const int maxn = 1e4+;
const int mod = +;
typedef pair<int,int> pii;
#define X first
#define Y second
#define pb push_back
//#define mp make_pair
#define ms(a,b) memset(a,b,sizeof(a))
const int inf = 0x3f3f3f3f;
#define lson l,m,2*rt
#define rson m+1,r,2*rt+1
typedef long long ll;
#define N 1000010
struct node {
double a,b;
}square[]; int cmp(node x,node y){
return x.b>y.b;
} int main(){
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
int n;
double l,w;
double r,p;
while(~scanf("%d%lf%lf",&n,&l,&w)){
int tot=;
for(int i=;i<n;i++){
scanf("%lf%lf",&p,&r);
if(r<=w/) continue;
square[tot].a=p-sqrt(r*r-w*w/);
square[tot++].b=p+sqrt(r*r-w*w/);
} sort(square,square+tot,cmp); double st=;
int ans=; while(st<l){
int i;
for(i=;i<tot;i++){
if(square[i].a<=st && square[i].b>st){
st=square[i].b;
ans++;
break;
}
}
if(i==tot) break;
}
if(st<l){
puts("-1");
}else{
printf("%d\n",ans);
}
}
return ;
}

UVA 10382 Watering Grass(区间覆盖)的更多相关文章

  1. UVA 10382 - Watering Grass【贪心+区间覆盖问题+高精度】

    UVa 10382 - Watering Grass n sprinklers are installed in a horizontal strip of grass l meters long a ...

  2. UVA 10382 Watering Grass 贪心+区间覆盖问题

    n sprinklers are installed in a horizontal strip of grass l meters long and w meters wide. Each spri ...

  3. UVA 10382 Watering Grass(区间覆盖,贪心)题解

    题意:有一块草坪,这块草坪长l 米,宽 w 米,草坪有一些喷头,每个喷头在横坐标为 p 处,每个喷头的纵坐标都是(w/2) ,并且喷头的洒水范围是一个以喷头为圆心,半径为 r 米的圆.每次最少需要打开 ...

  4. UVa 10382 Watering Grass (区间覆盖贪心问题+数学)

    题意:有一块长为l,宽为w的草地,在其中心线有n个喷水装置,每个装置可喷出以p为中心以r为半径的圆, 选择尽量少的装置,把草地全部润湿. 析:我个去啊,做的真恶心,看起来很简单,实际上有n多个坑啊,首 ...

  5. UVA 10382 Watering Grass (区间覆盖,贪心)

    问题可以转化为草坪的边界被完全覆盖.这样一个圆形就换成一条线段. 贪心,从中选尽量少的线段把区间覆盖,按照把线段按左端点排序,记录一个当前已经覆盖区间的位置cur, 从左端点小于等于cur选一个右端点 ...

  6. uva 10382 - Watering Grass(区域覆盖问题)

    Sample Input 8 20 2 5 3 4 1 1 2 7 2 10 2 13 3 16 2 19 4 3 10 1 3 5 9 3 6 1 3 10 1 5 3 1 1 9 1 Sample ...

  7. UVa 10382 - Watering Grass

    题目大意:有一条长为l,宽为w的草坪,在草坪上有n个洒水器,给出洒水器的位置和洒水半径,求能浇灌全部草坪范围的洒水器的最小个数. 经典贪心问题:区间覆盖.用计算几何对洒水器的覆盖范围简单处理一下即可得 ...

  8. UVa 10382 - Watering Grass 贪心,水题,爆int 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  9. UVA - 10382 Watering Grass(几何)

    题意:有一个矩形,n个圆.已知矩形的长宽和圆的半径,问最少需多少个圆将矩形完全覆盖. 分析: 1.首先求圆与矩形的长的交点,若无交点,则一定不能对用最少的圆覆盖矩形有贡献. 2.如果两个圆与矩形相交所 ...

随机推荐

  1. [转帖] IIS经典模式和集成模式的区别

    在 IIS 7.0 中,应用程序池有两种运行模式:集成模式和经典模式. https://blog.csdn.net/hongwei_23/article/details/44300923 这里面添加一 ...

  2. ESXi内虚拟机带快照与不带快照的情况下简单性能对比.

    1. 两个虚拟机配置相同都为2vCPU 8G内存 一个虚拟机内包含较多的快照且有内容梗概 一个虚拟机不包含快照直接只有一个虚拟机的vmdk磁盘文件 操作系统未windows server 2008r2 ...

  3. Oracle 的ORION工具简单使用

    1. 下载地址: http://www.oracle.com/technetwork/cn/topics/index-088165-zhs.html 2. linux x64 还有 windows的 ...

  4. 软件工程_3rd weeks

    本周上课的第一件事就是四人组队做工程,因为之前没有太多的准备,所以过程有些仓促,只是最后的结果是好的.有了自己的队伍和课题.感觉就应该这样,平时的我们比较随意,没有一丝的紧迫感,这样会督促着我们完成任 ...

  5. pandas绘图

    #encoding:utf8 import pandas as pd import numpy as np import matplotlib.pyplot as plt df = pd.DataFr ...

  6. html 头部 head

    head里面包含标签有: title:html名称,每个html文档都必须有 形式:<title>名字</title>,文档区不显示,浏览器可以识别: 浏览器工具栏显示的页面标 ...

  7. cxf 方法添加注解

    /** * 登录 * @param uid * @param password * @return */ @POST @Path(value = "/login") public ...

  8. BZOJ2819Nim——树链剖分+线段树+Nim游戏

    题目描述 著名游戏设计师vfleaking,最近迷上了Nim.普通的Nim游戏为:两个人进行游戏,N堆石子,每回合可以取其中某一堆的任意多个,可以取完,但不可以不取.谁不能取谁输.这个游戏是有必胜策略 ...

  9. 最短路径——SPFA算法

    一.前提引入 我们学过了Bellman-Ford算法,现在又要提出这个SPFA算法,为什么呢? 考虑一个随机图(点和边随机生成),除了已确定最短路的顶点与尚未确定最短路的顶点之间的边,其它的边所做的都 ...

  10. [hgoi#2019/2/16t3]psolve

    题目描述 Dustar有n道题目要做.他的月薪是m元. 由于题目是一流的难题,所以Dustar不得不找个人来帮(代)助(替)他写作业. 找人写作业不是免费的,但是他们能保证在一个月内做出任何题目.每做 ...