10382 - Watering Grass
来源:互联网 发布:手机怎么打开php视频 编辑:程序博客网 时间:2024/05/21 17:14
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-8struct 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;}
- UVa 10382 Watering Grass
- UVa 10382 - Watering Grass
- UVa 10382 - Watering Grass
- uva 10382 - Watering Grass
- uva 10382 - Watering Grass
- Uva 10382 - Watering Grass
- UVAOJ--10382 Watering Grass
- 10382 - Watering Grass
- Uva-10382-Watering Grass
- UVA 10382 Watering Grass
- 10382 - Watering Grass
- UVa:10382 Watering Grass
- uva 10382 Watering Grass
- uva 10382 - Watering Grass
- UVA 10382 - Watering Grass
- uva 10382 Watering Grass
- uva-10382-Watering Grass
- UVa 10382 - Watering Grass
- C语言父子进程shell命令重定向到管道传递(双管道)
- 剑指Offer算法实现之十三:在O(1)时间删除链表节点
- hdu 1052 Tian Ji -- The Horse Racing
- poj3140 树状dp
- objective-c 内存管理小结
- 10382 - Watering Grass
- HDU2066 一个人的旅行 解题报告--Dijkstra
- SDKD Single training #10未完成题目
- 胜利大逃亡 hdu 1253 三维
- 07-php中的方法重写
- XCode中调整字体大小
- bloom filter
- hdu 1506 Largest Rectangle in a Histogram
- swift命令行操作