贪心算法。

#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. 题解 P3200 【[HNOI2009]有趣的数列】

    说起来这是今天第三道卡特兰数了... 楼上的几篇题解好像都是直接看出这是卡特兰数,所以我就写一下为什么这道题可以用卡特兰数吧. 考察这样相邻的两项:\(a_{2i-1}\)与\(a_{2i}\),根据 ...

  2. Mysql写出高质量的sql语句的几点建议

    CleverCode在实际的工作也写过一些低效率的sql语句.这些语句会给数据库带来非常大的压力.最基本的表现就是sql语句执行慢,后来逐渐的去优化和尝试. 总结了一些高质量的sql语句的写法.这里C ...

  3. mysql-面试题目1

    一.数据库的ACID 原子性(Atomicity):保证事务中的所有操作全部执行或全部不执行. 一致性(Consistency):保证数据库始终保持数据的一致性——事务操作之前和之后都是一致的. 隔离 ...

  4. zoj_3657,12年长春站c题,模拟

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> us ...

  5. 福建省赛-- Common Tangents(数学几何)

    Problem B Common Tangents Accept: 191    Submit: 608 Time Limit: 1000 mSec    Memory Limit : 32768 K ...

  6. LBP(Local Binary Patterns)局部二进制模式

    1. LBP 用于人脸识别 为了预测每个像素属于哪个脸部器官(眼睛.鼻子.嘴.头发),通常的作法是在该像素周围取一个小的区域,提取纹理特征(例如局部二值模式),再基于该特征利用支持向量机等浅层模型分类 ...

  7. java9新特性-20-Javascript引擎升级:Nashorn

    1.官方Feature 236: Parser API for Nashorn 292: Implement Selected ECMAScript 6 Features in Nashorn 2.使 ...

  8. Android项目实战(五十五):部分机型点击home再点图标进入程序不保留再之前界面的问题

    解决办法: 1.在基类Activity中 添加方法 @Override public boolean moveTaskToBack(boolean nonRoot) { return super.mo ...

  9. hiho147周 - 数据结构 bitset

    题目链接 n个5维数,对于每个数,输出小于他的数的个数(每个维度都比他小); #include <cstdio> #include <cstring> #include < ...

  10. NodeJS学习笔记 (10)网络TCP-net(ok)

    模块概览 net模块是同样是nodejs的核心模块.在http模块概览里提到,http.Server继承了net.Server,此外,http客户端与http服务端的通信均依赖于socket(net. ...