问题可以转化为草坪的边界被完全覆盖。这样一个圆形就换成一条线段。

贪心,从中选尽量少的线段把区间覆盖,按照把线段按左端点排序,记录一个当前已经覆盖区间的位置cur,

从左端点小于等于cur选一个右端点最大的作为这次选的区间,如果没有符合条件的,说明不可能完全覆盖。

r*r会爆int...

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e4+;
int n,l,w;
struct seg
{
double l,r;
bool operator < (const seg& rh)const {
return l < rh.l;
}
}L[maxn]; int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d%d%d",&n,&l,&w)){
double d = w*w/.;
int ss = ;
for(int i = ; i < n; i++){
int p,r; scanf("%d%d",&p,&r);
if(*r<=w) {
continue;
}
double dx = sqrt(.*r*r-d);
L[ss].l = p-dx; L[ss++].r = p+dx;
}
sort(L,L+ss);
double cur = .; bool fg = false;
int ans = ; for(int i = ; i < ss;){
int j = i;
double nxt = cur;
while(j<ss && L[j].l <= cur) {
if(L[j].r > nxt) nxt = L[j].r;
j++;
}
if(j == i) break;
ans++;
cur = nxt;
i = j;
if(cur>=l){ fg = true; break; }
} if(fg) printf("%d\n",ans);
else puts("-1");
}
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(区间覆盖,贪心)题解

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

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

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

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

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

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

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

  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. DP专题

    最全DP总结 https://blog.csdn.net/cc_again/article/details/25866971 ACM题集 https://blog.csdn.net/liuqiyao_ ...

  2. 计蒜课/ 微软大楼设计方案/中等(xjb)

    题目链接:https://nanti.jisuanke.com/t/15772 题意:中文题诶- 思路:对于坐标为p1(x1, y1), p2(x2, y2) 的两个核心, 其中 x1 <= x ...

  3. 使用Unity容器实现属性注入

    简介 Unity :是微软用C#实现的轻量级,可扩展的依赖注入容器. 控制反转:(Inversion of Control,缩写为IoC),是用来消减程序之间的耦合问题,把程序中上层对下层依赖,转移到 ...

  4. How to install your SSL Certificate to your Windows Server

    Installation: Open the ZIP file containing your certificate. Save the file named your_domain_name.ce ...

  5. 通过T4模板解决EF模型序列号的循环引用问题

    在模型的T4模板(如model.tt)中插入如下代码,这样由模板生成的模型代码中的导航属性将自动带有[JsonIgnore]标识,不会被序列化 1. 添加命名空间的引用 找到以下代码,添加using ...

  6. 用户登录之记住密码 Cookie实现

  7. day5字典作业详解

    1.day5题目 1.有如下变量(tu是个元祖),请实现要求的功能 tu = ("alex", [11, 22, {"k1": 'v1', "k2&q ...

  8. css3椭圆运动

    通过使用css3实现让元素椭圆运动.而不是圆形运动. 效果1:http://sandbox.runjs.cn/show/ignefell 效果2:http://runjs.cn/code/w2wxjy ...

  9. BZOJ 4668: 冷战 并查集&&暴力LCA(雾)

    利用并查集按秩合并,保存每个点合并的时间: 求时间时,就一直跳u=fa[u],并记录路径上时间的最大值,代表最后一次合并的时间 #include<cstdio> #include<i ...

  10. ExpandoObject的使用

    IDictionary<string, object> obj = new System.Dynamic.ExpandoObject(); obj.Add(); dynamic obj2 ...