UVA 10382 - Watering Grass【贪心+区间覆盖问题+高精度】
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
2
-1
#include <bits/stdc++.h>
using namespace std;
inline int read()
{
int x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')
f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
inline void write(int x)
{
if(x<)
{
putchar('-');
x=-x;
}
if(x>)
{
write(x/);
}
putchar(x%+'');
}
struct Node
{
double x,y;
}p[];
int cmp(const Node &a,const Node &b)
{
if(a.x<b.x)
return ;
else
return ;
}
int main()
{
int n;
double l,w;
while(scanf("%d%lf%lf",&n,&l,&w)!=EOF)
{
for(int i=;i<n;i++)
{
double s,r;
scanf("%lf%lf",&s,&r);
if(r<w/2.0-1e-||fabs(r-w/2.0)<1e-)
{
i--;
n--;
continue;
}
double x=sqrt(r*r-w*w/4.0);
p[i].x=s-x;
p[i].y=s+x;
if(p[i].x<1e-)
p[i].x=;
if(p[i].y>l+1e-)
p[i].y=l;
}
sort(p,p+n,cmp);
if(fabs(p[].x)>1e-)
{
printf("-1\n");
continue;
}
double pos=,maxx=;
int sum=;
while()
{
if(pos>=l)
break;
maxx=;
for(int i=;i<n;i++)
if((p[i].x<pos-1e-||fabs(p[i].x-pos)<1e-)&&p[i].y>pos+1e-)
{
if(p[i].y>maxx+1e-)
{
maxx=p[i].y;
}
}
if(fabs(maxx)<1e-)
{
sum=;
break;
}
sum++;
pos=maxx;
}
if(sum==)
printf("-1\n");
else
printf("%d\n",sum);
}
return ;
}
UVA 10382 - Watering Grass【贪心+区间覆盖问题+高精度】的更多相关文章
- 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(区间覆盖)
n sprinklers are installed in a horizontal strip of grass l meters long and w meters wide. Each spri ...
- 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 贪心,水题,爆int 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVa 10382 - Watering Grass
题目大意:有一条长为l,宽为w的草坪,在草坪上有n个洒水器,给出洒水器的位置和洒水半径,求能浇灌全部草坪范围的洒水器的最小个数. 经典贪心问题:区间覆盖.用计算几何对洒水器的覆盖范围简单处理一下即可得 ...
- UVA 10020 Minimal coverage(贪心 + 区间覆盖问题)
Minimal coverage The Problem Given several segments of line (int the X axis) with coordinates [Li, ...
随机推荐
- adb指令介绍
一.adb命令格式为:adb [-d|-e|-s <serialNumber>] <command> 1.adb devices :列出当前电脑所连接的所有安卓设备 2.adb ...
- Android 再按一次退出程序三种办法
在Xamarin android中双击返回键退出程序的第一种做法 思路就是当用户按下返回键的时间超过两秒就退出,根据Keycode.Back判断用户按下的是返回键,重写这个OnKeyDown Date ...
- bzoj 1855: [Scoi2010]股票交易
Description 最近lxhgww又迷上了投资股票,通过一段时间的观察和学习,他总结出了股票行情的一些规律. 通过一段时间的观察,lxhgww预测到了未来T天内某只股票的走势,第i天的股票买入价 ...
- php html5 文件上传 (原创)
今天自己写了一个HTML5+FileReader+php 的文件上传,ajax异步上传也支持 git 下载:git clone https://github.com/jiechengyang/HTML ...
- django xdmin使用
我们来看看我们原先django给我们自带的admin后台是什么样子的呢 有人说,你的界面怎么那么丑,我说这个还叫丑吗,他说丑,我说你来,我看看你的,上图 看到登录界面后,我说别看了,我去修改,修改,我 ...
- js随机数生成,生成m-n的随机数
使用js生成n到m间的随机数字,主要目的是为后期的js生成验证码做准备,Math.random()函数返回0和1之间的伪随机数 var random = Math.random(); console. ...
- Xamarin 简单的网络请求
//try //{ // var httpReq = (HttpWebRequest)HttpWebRequest.Create(new Uri(re ...
- win10使用u盘装回win7
背景:一朋友要我帮忙把系统从win10装回到win7,因为做IT的嘛,想想也难不倒我,况且以前也经常重装系统,硬盘里就有win7的系统,于是很爽快的答应了.电脑拿过来一试才知道原来有这么多坑,原来的系 ...
- Python+selenium+eclipse+pydev自动化测试环境搭建
一. 安装python 1.下载安装python 可访问python的官方网站:http://www.Python.prg找到下载页面下载需要的版本,可下载python2.x或者pyth ...
- Nginx集群之WCF分布式消息队列
目录 1 大概思路... 1 2 Nginx集群之WCF分布式消息队列... 1 3 MSMQ消息队列... 2 4 编写WCF服务.客户端程序... ...