题目大意:有一条长为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. Eclipse最有用的快捷键

    编辑 Ctrl+1 快速修复(最经典的快捷键,就不用多说了,可以解决很多问题,比如import类.try catch包围等) Ctrl+Shift+F 格式化当前代码 Ctrl+Shift+M 添加类 ...

  2. jq中的css-Dom

    1,height() ,width() 此方法用来获取匹配元素的高和宽的值,如果括号内有值,则是修改匹配元素的值, 2.offset() 此方法的作用是获取元素在当前视窗的相对偏移,其中返回的对象包含 ...

  3. StreamReader 读取文本文件乱码问题

    解决读取文本文件乱码问题.我采取的是读取前先判断文本文件格式. StreamReader sr = new StreamReader(fullfileName, GetFileEncodeType(f ...

  4. C#中Form窗体中读取EXCEL的数据

    使用OLEDB可以对excel文件进行读取,我们只要把该excel文件作为数据源即可 首先引用Microsoft.EXEL 代码如下: using System; using System.Colle ...

  5. getHibernateTemplate()

    getHibernateTemplate 前提条件:你的类必须继承HibernateDaoSupport 一: 回调函数: public List getList(){   return (List ...

  6. 关于数据结构的10个面试题(c语言实现)

    关于数据结构的10个面试题(c语言实现) 2010-04-21 22:17 5702人阅读 评论(0) 收藏 举报 数据结构面试c语言bttree 1.         输入一个链表的头结点,从尾到头 ...

  7. 安卓布局修改基础常识篇之TextView属性

    [天使]安卓布局修改基础常识篇之TextView属性 在修改布局xml文件时需要熟练掌握一些属性,以下是TextView也就是文本的属性:android:autoLink 是否自动链接网址或邮箱地址: ...

  8. 兼容性,float

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  9. Ubuntu + VMware=Linux虚拟机

    1.工具 2.要点 3.问题 有时间再写

  10. phpstorm9如何配置interpreter

    找到php.exe的路径. 把php.exe 放进去就ok了