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选一个右端点 ...
随机推荐
- animationWithKeyPath键值对
animationWithKeyPath键值对的方式来改变动画 <Jacky Shin:可以从这个网址查到哪些可以做为动画效果, 打开xcode帮助,搜索animatable propertie ...
- Linux 关于解压
1.*.tar 用 tar –xvf 解压 2.*.gz 用 gzip -d或者gunzip 解压 3.*.tar.gz和*.tgz 用 tar –xzf 解压 4.*.bz2 用 bzip2 -d或 ...
- (java)从零开始之--异常处理(以文件拷贝为例)
开发过程中避免不了对异常的处理,但是异常的处理又不能乱throw 下面是简单的抛异常处理 public static void CopyFile(String souFile,String dirFi ...
- cocos2dx 实现华丽丽的滚动层.
前言 好久没写博客了. 前几周策划要求实现一个比较多功能的滚动层控件. 这个艰巨的任务就这样自然而然的落在了我这小身板上. 当然了, 只要我出手, 难度再高的需求也变得不堪一击. 哈哈哈哈 示例图 该 ...
- 浅谈 trie树 及其实现
定义:又称字典树,单词查找树或者前缀树,是一种用于快速检索的多叉树结构, 如英文字母的字典树是一个26叉树,数字的字典树是一个10叉树. 核心思想:是空间换时间.利用字符串的公共前缀来降低查询时间的开 ...
- NPOI使用手册
HSSFSheet sheet = hssfworkbook.CreateSheet("new sheet"); // Create a row and put some cell ...
- PHP之验证码识别
首先推荐几篇有关验证码识别的文章,觉得不错 php实现验证码的识别(初级篇) 关于bp神经网格识别验证码 一.思路 碰见一个验证码,如果我们想要识别它,我们需要的是做什么呢? 我们先观察几个验证码.. ...
- django访问sqlserver中的坑
首先不用说先安装django-sqlserver pip install django-sqlserver 然后在settings.py中修改'ENGINE': 'sqlserver_ado', ...
- Unity3D Quaternion各属性和函数测试
Quaternion属性与方法 一,属性: x.y.z就不说了,只看一个eulerAngles,代码如下: public Quaternion rotation = Quaternion.identi ...
- MySQL ubuntu启动
service mysql start 启动 service mysql restart 重启 service mysql stop 停止 mysql -uroot -ppassword 登入mysq ...