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 ;
}

最新文章

  1. 一步步调试解决iOS内存泄漏
  2. 单机最大tcp连接数
  3. JavaScript高级程序设计之表单基础
  4. IO多路复用的几种实现机制的分析
  5. vnc执行,报xauth could not run
  6. getopt getopt_long
  7. 用C++语言开发Android程序 配置开发环境
  8. 201521123070 《JAVA程序设计》第4周学习总结
  9. 网络协议 10 - Socket 编程(上):实践是检验真理的唯一标准
  10. SpringBoot之oauth2.0学习之服务端配置快速上手
  11. 【Linux】MySQL配置
  12. 使用R进行分组统计
  13. C#实现相似QQ的隐藏浮动窗口、消息闪动
  14. linux sort 多列正排序,倒排序
  15. z-index详细攻略
  16. 2017北京国庆刷题Day3 afternoon
  17. cocos2d-x HelloWorld 代码一撇
  18. PushState+Ajax实现简单的单页面应用SPA
  19. 使用 P3P 规范让 IE 跨域接受第三方 cookie
  20. java reflect反射---Java高级开发必须懂的

热门文章

  1. Selenium vs TestStudio,Selenium Grid vs F2Test
  2. [转]curl的详细使用
  3. js實現
  4. python之pygal:掷一个骰子统计次数并以直方图形式显示
  5. iOS程序的启动执行顺序
  6. 关于js特效轮播图练习
  7. EF 更新 删除
  8. Codeforces Round #419 (Div. 2) C. Karen and Game
  9. windows下安装PyTorch0.4.0
  10. nowcoder172C 保护 (倍增lca+dfs序+主席树)