题目链接: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. 手机WebAPP设计注意事项和解决方法

    1. 基本手机网页设计 1.1 wap端的网站表头 wap端的网站,写的时候首先注意表头,因为是手机端的,所以和我们平常用的web端页面的不一样,表头为: 1.2 尽量少使用水平滚动. 水平滚动除了比 ...

  2. PHPCMS 多站点管理切换问题

    打开系统函数库global.func.php 可以看到获取站点ID的函数如下 /** * 获取当前的站点ID */ function get_siteid() { static $siteid; if ...

  3. BPEL是个什么东东

    研究团队有个做智能服务组合的,其中用到叫BPEL的东西,因为全称是Business Process Execution Language,译成中文就是商业执行过程语言,这个东东的是整合SOA的一个执行 ...

  4. MapKit的使用显示当前位置

    1.添加MapKit.framework框架 ,在plist中添加字段,用于,获取用户当前位置设置 NSLocationAlwaysUsageDescription 2.代码 #import &quo ...

  5. Linux环境变量设置指南

    以配置java环境变量为例 目录 [隐藏]  1 修改/etc/profile文件 2 修改用户目录下的.bash_profile 3 修改.bashrc文件 4 直接在shell下设置 5 查看环境 ...

  6. javascript写在<head>和<body>里的区别

    Javascript写在哪里?概括起来就是三种形式:1. 内部:Html网页的<body></body>中:2. 内部:Html网页的<head></head ...

  7. ASP.NET MVC3 中整合 NHibernate3.3、Spring.NET2.0 时 Session 关闭问题

    一.问题描述 在向ASP.NET MVC中整合NHibernate.Spring.NET后,如下管理员与角色关系: 类public class Admin { public virtual strin ...

  8. PHP、Java输出json格式数据

      PHP 输出json. $result = mysql_query($sql); //查询结果 $users=array(); $i=0; while($row=mysql_fetch_array ...

  9. MFC 打开链接的方法

    第一种: system("start explorer http://http://www.baidu.com"); 第二种: ShellExecute(NULL, NULL, _ ...

  10. iOS 初学UITableView、UITableViewCell、Xib

    注意事项: 1.一个.xib里面最多设置一个cell 2.要仔细调整自动布局,其实它不太好用 3.记得设置<UITableViewDataSource>委托 4.记得在ViewContro ...