10382 - Watering Grass
Problem E
Watering Grass
Input: standard input
Output: standard output
Time Limit: 3 seconds
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
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define min 1e-8
struct data{double x; double y;}p[10005];
int cmp( const void *a ,const void *b)
{return (*(data *)a).x>(*(data *)b).x?1:-1;}
int main()
{
int n,l,w,x,r,i,j;
while(scanf("%d%d%d",&n,&l,&w)!=EOF)
{
int c=0,f=0,ans=0;
double s=0,e=0,d;
for(i=0;i<n;i++)
{
scanf("%lf%d",&d,&r);
if(r<w/2.0) continue;
double temp=sqrt((double)r*r-(double)w*w/4.0);
p[c].x=d-temp;
p[c].y=d+temp;
c++;
}
qsort(p,c,sizeof(p[0]),cmp);
for(i=0;i<c;i++)
if(p[i].x>e)
break;
else if(p[i].y>e)
{
for(j=i;j<c&&p[j].x-s<min;j++)
if(e-p[j].y<-min)
e=p[j].y;
ans++;
if(e>=l)
{f=1;break;}
s=e;
}
if(f)
printf("%d\n",ans);
else
printf("-1\n");
}
return 0;
}
10382 - Watering Grass的更多相关文章
- UVA 10382 - Watering Grass【贪心+区间覆盖问题+高精度】
UVa 10382 - Watering Grass n sprinklers are installed in a horizontal strip of grass l meters long a ...
- 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 贪心+区间覆盖问题
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
题目大意:有一条长为l,宽为w的草坪,在草坪上有n个洒水器,给出洒水器的位置和洒水半径,求能浇灌全部草坪范围的洒水器的最小个数. 经典贪心问题:区间覆盖.用计算几何对洒水器的覆盖范围简单处理一下即可得 ...
- 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 米,草坪有一些喷头,每个喷头在横坐标为 p 处,每个喷头的纵坐标都是(w/2) ,并且喷头的洒水范围是一个以喷头为圆心,半径为 r 米的圆.每次最少需要打开 ...
- UVa 10382 Watering Grass (区间覆盖贪心问题+数学)
题意:有一块长为l,宽为w的草地,在其中心线有n个喷水装置,每个装置可喷出以p为中心以r为半径的圆, 选择尽量少的装置,把草地全部润湿. 析:我个去啊,做的真恶心,看起来很简单,实际上有n多个坑啊,首 ...
- UVA 10382 Watering Grass (区间覆盖,贪心)
问题可以转化为草坪的边界被完全覆盖.这样一个圆形就换成一条线段. 贪心,从中选尽量少的线段把区间覆盖,按照把线段按左端点排序,记录一个当前已经覆盖区间的位置cur, 从左端点小于等于cur选一个右端点 ...
随机推荐
- oracle中不曾熟悉的 to_char、to_number(未完待续)
十进制 十六进制88 58 用法一:Converts a HEX number to o FLOAT (转换一个十六进制数的浮标) SQL> sele ...
- 请教如何实现UITextField值变化的实时监视
上网搜索以后发现基本的处理方法大概有三种1.KVO方式[textField addObserver:self forKeyPath:@"text" options:0 contex ...
- [LeetCode OJ]-Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- 记一个问题的AC
今天突然做一道LCT的染色问题的时候突然想到一个两个月前一道没有AC的题目. 链接 大意是,给一个长度为10^4的序列,最多有255个不同的数字,有最多10^5次方个询问,对于每个询问 l,r 输出[ ...
- xml 个人练习2
package cn.gdpe.xml; import java.io.File;import java.io.FileInputStream;import java.io.IOException;i ...
- CMD下查询Mysql中文乱码的解决方法
我的MySQL是默认utf8编码的,所建数据库也是设置utf8编码,使用程序可以新增中文数据,在cmd中使用SQL语句新增数据则报类似Incorrect string value: '\xB2\xE2 ...
- Android Context作用
Context 用于访问全局信息的接口 App的资源: strings, drawable资源等等 工程代码:LearnContext.zip ---------------------------- ...
- TatukGIS-TGIS_LayerVector-LocateEx
方法原型: function LocateEx(const _ptg: TGIS_Point; const _prec: Double; const _uid: Integer; var _dist: ...
- Standard Numeric Format Strings
The following table describes the standard numeric format specifiers and displays sample output prod ...
- Unity3d 基础知识学习 工具篇
Unity3d 层(layer)的学习 @广州小龙 unity中的层是个很有用的东西, 点击层的下拉框,点击Add Layer,可以打开层管理器,我新建了一个层为test 他的id值是8,这个后面会 ...