喷水装置的圆心和半径确定,就能确定左端和右端。开始时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. Linux - PWM的驱动编写【转】

    本文转载自:https://blog.csdn.net/u012264124/article/details/77482853 比如要用到pwm1,那么首先要保证这个pwm1并没有被别的驱动程序占用. ...

  2. 远程调试Spring项目

    目录 服务端启动: 启动jar包: 使用环境变量参数调试jar包: 使用mvnDebug启动SpringMVC项目: 使用mvn启动: 使用Tomcat,非嵌入式启动: 客户端设置: IDEA设置: ...

  3. hihoCoder week3 KMP算法

    题目链接 https://hihocoder.com/contest/hiho3/problems kmp算法 #include <bits/stdc++.h> using namespa ...

  4. 题解——洛谷 P2680 NOIP提高组 2015 运输计划

    树上差分加上二分答案 详细题解待填坑 #include <cstdio> #include <algorithm> #include <cstring> using ...

  5. 论文阅读之:Deep Meta Learning for Real-Time Visual Tracking based on Target-Specific Feature Space

    Deep Meta Learning for Real-Time Visual Tracking based on Target-Specific Feature Space  2018-01-04  ...

  6. 《开始使用Linux》单元测验 1

    C语言编写的应用程序,通过printf打印一个换行符\n,但在终端上执行的是回车加换行\r\n,把换行符替换为回车换行是由下面哪个软件模块完成的? Linux内核中的行律模块 下面哪个命令可以获得ma ...

  7. Latex: 添加IEEE会议论文作者信息

    参考: Multiple Authors with common affiliations in IEEEtran conference template Latex: 添加IEEE会议论文作者信息 ...

  8. Lintcode521-Remove Duplicate Numbers in Array-Easy

    Description Given an array of integers, remove the duplicate numbers in it. You should: Do it in pla ...

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

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

  10. C#窗口禁止移动的方法

    1,窗口属性中有locked属性,设置为true. (在自己进行编码的时候并没能找到这个属性,貌似只能在窗口设计时进行设置,故此方法无可控性) 2,窗口属性中有FormBorderStyle属性,设置 ...