UVA 10382 Watering Grass(区间覆盖)
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(区间覆盖)的更多相关文章
- UVA 10382 - Watering Grass【贪心+区间覆盖问题+高精度】
UVa 10382 - Watering Grass n sprinklers are installed in a horizontal strip of grass l meters long a ...
- UVA 10382 Watering Grass 贪心+区间覆盖问题
n sprinklers are installed in a horizontal strip of grass l meters long and w meters wide. Each spri ...
- UVA 10382 Watering Grass(区间覆盖,贪心)题解
题意:有一块草坪,这块草坪长l 米,宽 w 米,草坪有一些喷头,每个喷头在横坐标为 p 处,每个喷头的纵坐标都是(w/2) ,并且喷头的洒水范围是一个以喷头为圆心,半径为 r 米的圆.每次最少需要打开 ...
- UVa 10382 Watering Grass (区间覆盖贪心问题+数学)
题意:有一块长为l,宽为w的草地,在其中心线有n个喷水装置,每个装置可喷出以p为中心以r为半径的圆, 选择尽量少的装置,把草地全部润湿. 析:我个去啊,做的真恶心,看起来很简单,实际上有n多个坑啊,首 ...
- UVA 10382 Watering Grass (区间覆盖,贪心)
问题可以转化为草坪的边界被完全覆盖.这样一个圆形就换成一条线段. 贪心,从中选尽量少的线段把区间覆盖,按照把线段按左端点排序,记录一个当前已经覆盖区间的位置cur, 从左端点小于等于cur选一个右端点 ...
- 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 ...
- UVa 10382 - Watering Grass
题目大意:有一条长为l,宽为w的草坪,在草坪上有n个洒水器,给出洒水器的位置和洒水半径,求能浇灌全部草坪范围的洒水器的最小个数. 经典贪心问题:区间覆盖.用计算几何对洒水器的覆盖范围简单处理一下即可得 ...
- UVa 10382 - Watering Grass 贪心,水题,爆int 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVA - 10382 Watering Grass(几何)
题意:有一个矩形,n个圆.已知矩形的长宽和圆的半径,问最少需多少个圆将矩形完全覆盖. 分析: 1.首先求圆与矩形的长的交点,若无交点,则一定不能对用最少的圆覆盖矩形有贡献. 2.如果两个圆与矩形相交所 ...
随机推荐
- Javascript中实现继承的方式
js中实现继承和传统的面向对象语言中有所不同:传统的面向对象语言的继承由类来实现,而在js中,是通过构造原型来实现的,原型与如下几个术语有关: ①构造函数:在构造函数内部拥有一个prototype属性 ...
- Linux命令博客目录
Linux 目录结构 Linux命令(一) pwd ,cd Linux命令(二) 复制文件 cp Linux命令(三) 移动文件 mv Linux命令(四)删除文件 rm Linux终端常用快捷键 L ...
- cerr与cout的区别
1.cout经过缓冲后输出,默认情况下是显示器.可以重定向. 2.cerr不经过缓冲而直接输出,一般用于迅速输出出错信息,不可以被重定向.
- python decimal.quantize()参数rounding的各参数解释与行为
我最开始其实是由于疑惑ROUND_FLOOR和 ROUND_DOWN的表现区别才看了一波文档,但是感觉拉出一票以前没有留意过的东西. 贴一个decimal文档里面的解释: ROUND_CEILING ...
- jsp servlet 的 请求转发和重定向
以前对于servlet和servlet/jsp之间的跳转路径问题感到很迷惑,今天亲自动手实验了一把,总结如下: servlet已经是项目根路径下面的资源了,所以servlet跳转的时候,在跳转路径上面 ...
- 深度学习中 Batch Normalization
深度学习中 Batch Normalization为什么效果好?(知乎) https://www.zhihu.com/question/38102762
- git-stash用法小结
[时间:2016-10] [状态:Open] [关键词:git,版本控制,版本管理,stash,git储藏] 缘起 今天在看一个bug,之前一个分支的版本是正常的,在新的分支上上加了很多日志没找到原因 ...
- ef group 封装
表达式树,传递 group public class Test<T> where T : class { MoviesEntities db = new MoviesEntities(); ...
- itexpdf同一个段落不同文字,如何设置不同的格式
Java使用itexpdf生成PDF,正常情况下,新建一个段落Paragraph,然后可以给段落添加一个格式BaseFont Paragraph paragraphBlue = new Paragra ...
- 使用ntlmrelayx在任何地方进行中继凭据
0x00 前言 通过Fox-IT我们可以让客户了解其企业组织中出现的常见安全风险.当攻击者可以利用NT LAN Manager身份验证协议(以下简称:NTLM身份验证)时,凭据重用就有这样的风险,即这 ...