贪心算法。

#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. 笔记本win2008 r2的hyper-v安装centos

    一.i5以上cpu支持虚拟化,不过默认是关闭的,先到bios设置里把虚拟功能打开: 二.“服务器管理器”->“角色”里安装hyper-v并重启: 三.设置无线网络桥接,有线就不需要了,具体如下: ...

  2. 洛谷 P2128 赤壁之战

    P2128 赤壁之战 题目描述 赤壁之战,黄盖率舰满载薪草膏油诈降曹军. 受庞统所授的连环计,曹军战船之间由铁索相连,没有两艘战船在同一位置,也没有铁索两两相交或穿过战船.每艘船都有其一定的战略价值. ...

  3. hdoj 1429 胜利大逃亡(续) 【BFS+状态压缩】

    题目:pid=1429">hdoj 1429 胜利大逃亡(续) 同样题目: 题意:中文的,自己看 分析:题目是求最少的逃亡时间.确定用BFS 这个题目的难点在于有几个锁对于几把钥匙.唯 ...

  4. HDOJ 2828 Lamp DLX反复覆盖

    DLX反复覆盖模版题: 每一个开关两个状态.但仅仅能选一个,建2m×n的矩阵跑DLX模版.. .. Lamp Time Limit: 2000/1000 MS (Java/Others)    Mem ...

  5. 用Go语言写了一个电脑搜索文件的小东西

    package main import ( "bytes" "fmt" "os" "os/exec" "pat ...

  6. mysql-数据库维护

    一.备份数据 1.使用mysqldump命令备份:前提:musql的版本必须一致. mysqldump -u username -p  --default -character-set=gbk dbn ...

  7. C++ 何时使用动态分配(即使用newkeyword)?何时使用指针?

    动态分配 在你的问题里.你用了两种方式创建对象.这两种方式基本的不同在于对象的存储时间. 当运行Object myObject;这句代码时.它作为自己主动变量被创建,这意味着当对象出了作用域时也会自己 ...

  8. C# - Thread.Join()

    Blocks the calling thread until a thread terminates, while continuing to perform standard COM and Se ...

  9. 5.array

    #include <iostream> #include <array> #include <algorithm> using namespace std; //a ...

  10. POJ 3280 DP

    题意: 思路: DP f[i][j]表示把i到j变成回文串的最少代价 f[start][end]=f[start+1][end]+min(node[a[start]].del,node[a[start ...