贪心算法。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
struct Node
{
double lx;
double rx;
}node[];
bool cmp(Node a,Node b)
{
return a.lx<b.lx;
}
int main()
{
double n,m,w,l,r;
while(scanf("%lf%lf%lf",&n,&m,&w)!=EOF)
{
int x=,i,j,ans=,ok=;
for(int i=;i<n;i++)
{
scanf("%lf%lf",&l,&r);
if(w/>=r) continue;
double t=(double)sqrt(r*r-((w*w)/4.0));
node[x].lx=l-t;
node[x].rx=l+t;
x++;
}
sort(node,node+x,cmp);
double left=0.0,right=0.0;
if(node[].lx<=)
{
i=;
while(i<x)
{
j=i;
while(j<x && node[j].lx<=left)
{
if(node[j].rx>right)
{
right=node[j].rx;
}
j++;
}
if(i==j) break;
i=j;
ans++;
left=right;
if(left>=m)
{
ok=;
break;
}
}
}
if(ok)printf("%d\n",ans);
else printf("-1\n");
}
return ;
}

UVA Watering Grass的更多相关文章

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

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

  2. 10382 - Watering Grass

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

  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

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

  5. UVa 10382 - Watering Grass

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

  6. UVa 10382 - Watering Grass 贪心,水题,爆int 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

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

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

  8. UVA 10382 Watering Grass 贪心+区间覆盖问题

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

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

随机推荐

  1. Fiddler 接口测试(Composer)的使用方法

    原文:Fiddler 接口测试(Composer)的使用方法 下载地址:https://www.telerik.com/download/fiddler 一.Composer简介 右侧Composer ...

  2. 【codeforces 20B】Equation

    [题目链接]:http://codeforces.com/contest/20/problem/B [题意] 给你一个方程,让你输出这个方程的解的情况. [题解] a==0,b==0,c==0时,为恒 ...

  3. Java基础学习总结(1)——equals方法

    一.equals方法介绍 1.1.通过下面的例子掌握equals的用法 package cn.galc.test; public class TestEquals { public static vo ...

  4. hdu5137 How Many Maos Does the Guanxi Worth(单源最短路径)

    题目链接:pid=5137">点击打开链接 题目描写叙述:如今有一张关系网.网中有n个结点标号为1-n.有m个关系,每一个关系之间有一个权值.问从2-n-1中随意去掉一个结点之后,从1 ...

  5. 22.允许重复的容器(unordered_multiset)

    #include <string> #include <iostream> #include <unordered_set> using namespace std ...

  6. feign client传递对象

    http://bbs.springcloud.cn/d/134-feign-client server端申明 @RestController public class HelloController ...

  7. SSRS 报表 递归列表

    SSRS 报表 递归列表 .需要数据集合中两个必备字段 ID PID 1.添加数据集合,在图上标记的地方点击右键添加数据集合,根据需求自己编写 2.点击插入选项卡 中的 矩阵  有两种方式 一种是 矩 ...

  8. C语言基础-第一章

    1.常量 直接常量: int mm=100; float nn=100.01; 字符常量:   编译指令,#define 常量名 常量值   (预处理命令,预处理命令都#开头.成为宏命令)  关键字, ...

  9. TabHost的自定义

    使用自定义的TabHost可以不用继承TabActicity,但是要注意的是如果使用Activity作为Content的话,有两处代码是一定要加的.不然就会出现RuntimeError,还有在XML布 ...

  10. ACM-ICPC 2016 Qingdao Preliminary Contest

    A I Count Two Three I will show you the most popular board game in the Shanghai Ingress Resistance T ...