题目大意:有一条长为l,宽为w的草坪,在草坪上有n个洒水器,给出洒水器的位置和洒水半径,求能浇灌全部草坪范围的洒水器的最小个数。

  经典贪心问题:区间覆盖。用计算几何对洒水器的覆盖范围简单处理一下即可得到每个区间的范围,剩下的就是区间覆盖了。可参考UVa 10020 - Minimal coverage

 #include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define MAXN 10000+10 struct Interval
{
int pos, r;
double s, e;
bool operator < (const Interval& in) const
{
return s < in.s;
}
};
Interval interval[MAXN]; double cover(double c, double a)
{
return sqrt(c*c - a*a);
} int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int n, l, w;
while (scanf("%d%d%d", &n, &l, &w) != EOF)
{
for (int i = ; i < n; i++)
{
scanf("%d%d", &interval[i].pos, &interval[i].r);
double t = cover(interval[i].r, w/2.0);
interval[i].s = interval[i].pos - t;
interval[i].e = interval[i].pos + t;
}
sort(interval, interval+n);
double start = ;
int p = , ans = ;
bool ok = true;
while (start < l)
{
int q = p;
double lmax = -;
while (p < n && interval[p].s <= start)
{
if (interval[p].e > lmax) lmax = interval[p].e;
p++;
}
if (p == q || lmax <= start)
{
ok = false;
break;
}
ans++;
start = lmax;
}
if (ok) printf("%d\n", ans);
else printf("-1\n");
}
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 贪心,水题,爆int 难度: 0

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

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

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

  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(区域覆盖问题)

    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 ...

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

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

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

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

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

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

  9. UVA - 10382 Watering Grass(几何)

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

随机推荐

  1. Chrome 43+浏览器 Cookies encrypted_value解密脚本

    python 3.3.5 # -*- coding: utf-8 -*- # Used information from: # http://stackoverflow.com/questions/4 ...

  2. Integer自动装箱拆箱bug,创建对象在-128到127

    1 public class Demo3 { public static void main(String[] args) { Integer a = 1; Integer b = 2; Intege ...

  3. CGI接口原理及实现(转载)

    原文:http://blog.csdn.net/duola_rain/article/details/15812585 CGI接口原理及实现(2012-12-7 Over) 1.CGI定义: CGI( ...

  4. Android ART运行时无缝替换Dalvik虚拟机的过程分析

    Android ART运行时无缝替换Dalvik虚拟机的过程分析 分类: Android2014-01-13 00:59 42722人阅读 评论(66) 收藏 举报 AndroidARTDalvikV ...

  5. win7 64位andriod开发环境搭建

    本文转自:http://www.cfanz.cn/index.php?c=article&a=read&id=65289 最近换了新电脑,装了win7 64位系统,安装了各种开发环境, ...

  6. 杀死进程kill和fuser

    1 kill -9 id 2   不行的话使用    fuser -k -SIGHUP /opt/bre/cookiemapping/wsapi/123 fuser有一个特别的用法在于它可以一次杀死那 ...

  7. Android——init可执行程序

    init进程是Android启动后,系统执行的第一个名称为init的可执行程序. 功能: 设备管理 解析启动脚本init.rc 执行启动脚本中的基本功能 执行启动脚本中的各种服务 代码路径:syste ...

  8. fork,exec,source

    http://alsww.blog.51cto.com/2001924/1113112 http://stackoverflow.com/questions/1127502/start-stop-da ...

  9. ural1628 White Streaks

    White Streaks Time limit: 1.0 secondMemory limit: 64 MB The life of every unlucky person has not onl ...

  10. vector 的用法(c++)

    vertor是向量类型,它是一个对象实体.它作为容器可以容纳不同的实体,如int,flout,double,还有类类型. 1.包含头文件 #include <vector> 2.声明:ve ...