喷水装置的圆心和半径确定,就能确定左端和右端。开始时pos=0,选取左端小于pos,右端最大的更新pos。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
#define mkp make_pair
using namespace std;
const double EPS=1e-;
typedef long long lon;
const lon SZ=,INF=0x7FFFFFFF,mod=; struct nd{
double ll,rr;
nd(double a,double b):ll(a),rr(b){}
bool operator<(const nd& rbs)const
{
return ll<rbs.ll;
}
}; void init(int n,double wid,vector<nd> &vct)
{
for(int i=;i<n;++i)
{
double pi,ri;
cin>>pi>>ri;
if(ri>0.5*wid)
{
double delta=sqrt(ri*ri-0.25*wid*wid);
vct.push_back(nd(pi-delta,pi+delta));
}
}
sort(vct.begin(),vct.end());
} int work(double len,vector<nd> &vct)
{
double pos=;
int res=;
for(int i=;;)
{
double rm=;
for(;i<vct.size()&&(vct[i].ll<pos||fabs(vct[i].ll-pos)<EPS);++i)
{//注意限制i的条件写在前
rm=max(rm,vct[i].rr);
}
if(fabs(rm)<EPS)return -;
pos=rm;
++res;
if(pos>len||fabs(pos-len)<EPS)break;
if(i>=vct.size())return -;
}
//cout<<res<<endl;
return res;
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
lon casenum;
//cin>>casenum;
//cout<<casenum<<endl;
//for(lon time=1;time<=casenum;++time)
int n,len,wid;
for(int time=;cin>>n>>len>>wid;++time)
{
vector<nd> vct;
init(n,wid,vct);
cout<<work(len,vct)<<endl;
}
return ;
}

重复。

Watering Grass UVA - 10382的更多相关文章

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

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

  2. UVA 10382.Watering Grass-贪心

    10382 - Watering Grass Time limit: 3.000 seconds n sprinklers are installed in a horizontal strip of ...

  3. 10382 - Watering Grass

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

  4. Watering Grass(贪心)

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

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

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

  6. UVa 10382 - Watering Grass

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

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

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

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

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

随机推荐

  1. 【拼接属性查询方式】MySql某一列属性值为拼接时的查询方式

    数据库中某一列的值为 使用IN查询是无法查询到数据的,只能查询到IN(2)或者IN(2,3)  查询结果: , style_id) 正确方式:使用FIND_IN_SET函数 , style_id) , ...

  2. 深度学习课程笔记(一)CNN 卷积神经网络

    深度学习课程笔记(一)CNN 解析篇 相关资料来自:http://speech.ee.ntu.edu.tw/~tlkagk/courses_ML17_2.html 首先提到 Why CNN for I ...

  3. Tutorials on training the Skip-thoughts vectors for features extraction of sentence.

    Tutorials on training the Skip-thoughts vectors for features extraction of sentence.  1. Send emails ...

  4. (zhuan) Deep Deterministic Policy Gradients in TensorFlow

          Deep Deterministic Policy Gradients in TensorFlow AUG 21, 2016 This blog from: http://pemami49 ...

  5. (转载)Unity3D连接本地或局域网MySQL数据库

    准备工作: 1.打开 Unity3D 安装目录,到这个路径下 Editor > Data > Mono > lib > mono > 2.0 拷贝出下图的五个动态链接库, ...

  6. CAS 单点登录 移动端获取TGT、ST 已经移动端登录页面不进行跳转的设置

    一.设置移动客户端验证ST通过后,页面不进行302重定向跳转 修改web.xml <!--**************************************************** ...

  7. 【译】第20节---数据注解-InverseProperty

    原文:http://www.entityframeworktutorial.net/code-first/inverseproperty-dataannotations-attribute-in-co ...

  8. Codeforces Round #441 D. Sorting the Coins(模拟)

    http://codeforces.com/contest/876/problem/D 题意:题意真是难懂,就是给一串序列,第i次操作会在p[x](1<=x<=i)这些位置放上硬币,然后从 ...

  9. BioConda--转载

    1. Conda安装 如BioConda官网[1]所说,BioConda需要Conda安装环境,如果你使用过Anaconda python安装环境,那么你已经有了Conda安装环境,否则,最好的办法是 ...

  10. 【UOJ#196】【BZOJ4574】[Zjoi2016]线段树

    题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=4574 http://uoj.ac/problem/196 考虑数字随机并且值域够大,我们 ...