题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/E

题意:

给定一条草坪,草坪上有n个喷水装置。草坪长l米宽w米,n个装置都有每个装置的位置和喷水半径。要求出最少需要几个喷水装置才能喷满草坪。喷水装置都是装在草坪中间一条水平线上的。

案例:

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<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm>
#include<cmath>
using namespace std;
#define maxn 10100
int n,k;
double m,w,x,y;
struct node
{
double l;
double r;
}a[maxn];
int cmp( node a, node b) //按覆盖最远的排序(半径由大到小)
{ return a.r > b.r; }
int main()
{
while(scanf("%d%lf%lf",&n,&m,&w)!=EOF)
{
double L=;
k=;
int i=,j=;
double d;
while(n--)
{
scanf("%lf%lf",&x,&y);
d=sqrt(y*y-(w*w)/); //转化为矩形覆盖
a[j].l=x-d;
a[j++].r=x+d; }
sort(a,a+j,cmp);
while(L<m)
{ int i;
for(i=;i<j;i++)
{
if(a[i].l<=L&&a[i].r>L)
{
L=a[i].r;
k++;
break;
}
}
if(i==j) break;
}
if(L<m)
cout<<"-1"<<endl;
else
cout<<k<<endl;
}
return ;
}

Watering Grass的更多相关文章

  1. 10382 - Watering Grass

    Problem E Watering Grass Input: standard input Output: standard output Time Limit: 3 seconds n sprin ...

  2. UVA 10382 - Watering Grass【贪心+区间覆盖问题+高精度】

    UVa 10382 - Watering Grass n sprinklers are installed in a horizontal strip of grass l meters long a ...

  3. Watering Grass(贪心)

    Watering Grass n sprinklers are installed in a horizontal strip of grass l meters long and w meters ...

  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 贪心+区间覆盖问题

    n sprinklers are installed in a horizontal strip of grass l meters long and w meters wide. Each spri ...

  6. Watering Grass(贪心算法)

    给定一条草坪.草坪上有n个喷水装置.草坪长l米宽w米..n个装置都有每个装置的位置和喷水半径..要求出最少需要几个喷水装置才能喷满草坪..喷水装置都是装在草坪中间一条水平线上的. n sprinkle ...

  7. Uva 10382 (区间覆盖) Watering Grass

    和 Uva 10020几乎是一样的,不过这里要把圆形区域转化为能够覆盖的长条形区域(一个小小的勾股定理) 学习一下别人的代码,练习使用STL的vector容器 这里有个小技巧,用一个微小量EPS来弥补 ...

  8. 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 ...

  9. UVa 10382 - Watering Grass

    题目大意:有一条长为l,宽为w的草坪,在草坪上有n个洒水器,给出洒水器的位置和洒水半径,求能浇灌全部草坪范围的洒水器的最小个数. 经典贪心问题:区间覆盖.用计算几何对洒水器的覆盖范围简单处理一下即可得 ...

随机推荐

  1. 10 个学习iOS开发的最佳网站(转)

    10 个学习iOS开发的最佳网站 作者 jopen 2012-09-26 08:59:56 1) Apple Learning Objective C Objective-C,通常写作ObjC和较少用 ...

  2. loj 1357(树形dp)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1357 #define _CRT_SECURE_NO_WARNINGS #include ...

  3. VPS -Digital Ocean -初试以及VPN的搭建

    首先恭喜你找到这篇博客,它会带你走出困境. 题外话(请忽略):一直以来想搞一个VPS,终于在自己的刺激下试了一下Digital Ocean,还没有使用很长时间不做太多评论,唯一给我的感觉是各种操作还算 ...

  4. LoadRunner 事务函数

    status 包括LR_PASS, LR_FAIL,  LR_AUTO,  LR_STOP(这个没用过) lr_set_transaction_instance_status(status); 可以根 ...

  5. 【框架】网络请求+Gson解析--Retrofit 2

    其实内部是封装了Okhttp和Gson解析 public class CourseFragmentAPI { public static void get(String userId, BaseCal ...

  6. Codeforces Round #355 (Div. 2)-C

    C. Vanya and Label 题目链接:http://codeforces.com/contest/677/problem/C While walking down the street Va ...

  7. iOS10 UI设计基础教程

    iOS10 UI设计基础教程 介绍:本教程针对iOS初级开发人员,基于iOS 10系统,使用Swift 3.0语言讲解如何进行UI设计.本教程内容涵盖UI基础构成.UI元素.自动布局.自适应UI.UI ...

  8. spring MVC 的MultipartFile转File??

    MultipartFile file = xxx;         CommonsMultipartFile cf= (CommonsMultipartFile)file;         DiskF ...

  9. 01背包 ZOJ 3931 Exact Compression

    题目连接 题意:n个数字构建哈夫曼树,问是否存在这样一棵树使得:(Fi数字大小,Ci哈夫曼表示下,'0'的数量) 分析:每次从优先队列取出两个数字可以互换位置,这样可以01互换.设a[i] <= ...

  10. ajax 异步交互

    <script>     $(function(){         $("#sub").click(function () {             $.ajax( ...