Watering Grass UVA - 10382
喷水装置的圆心和半径确定,就能确定左端和右端。开始时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的更多相关文章
- UVA 10382 - Watering Grass【贪心+区间覆盖问题+高精度】
UVa 10382 - Watering Grass n sprinklers are installed in a horizontal strip of grass l meters long a ...
- UVA 10382.Watering Grass-贪心
10382 - Watering Grass Time limit: 3.000 seconds n sprinklers are installed in a horizontal strip of ...
- 10382 - Watering Grass
Problem E Watering Grass Input: standard input Output: standard output Time Limit: 3 seconds n sprin ...
- Watering Grass(贪心)
Watering Grass n sprinklers are installed in a horizontal strip of grass l meters long and w meters ...
- Uva 10382 (区间覆盖) Watering Grass
和 Uva 10020几乎是一样的,不过这里要把圆形区域转化为能够覆盖的长条形区域(一个小小的勾股定理) 学习一下别人的代码,练习使用STL的vector容器 这里有个小技巧,用一个微小量EPS来弥补 ...
- UVa 10382 - Watering Grass
题目大意:有一条长为l,宽为w的草坪,在草坪上有n个洒水器,给出洒水器的位置和洒水半径,求能浇灌全部草坪范围的洒水器的最小个数. 经典贪心问题:区间覆盖.用计算几何对洒水器的覆盖范围简单处理一下即可得 ...
- UVa 10382 - Watering Grass 贪心,水题,爆int 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVA 10382 Watering Grass(区间覆盖)
n sprinklers are installed in a horizontal strip of grass l meters long and w meters wide. Each spri ...
- UVA 10382 Watering Grass 贪心+区间覆盖问题
n sprinklers are installed in a horizontal strip of grass l meters long and w meters wide. Each spri ...
随机推荐
- QSetting
.初始化,判断是否存在ini文件,如果不存在则新建 void iniConfig() { QFileInfo fileInfo(".\\config.ini"); if (!fil ...
- uniGUI试用笔记(一)
通过向导创建一个uniGUI应用服务器,工程中有三个文件: TUniServerModule = class(TUniGUIServerModule) TUniMainModule = class(T ...
- win10安装Zookeeper3.4.12
为了方便在本地开发环境进行调试,希望在win10环境中安装一个zookeeper 安装: 下载: 下载最新的stable版 zookeeper-3.4.12.tar.gz 配置环境变量: ZOOKEE ...
- 【拼接属性查询方式】MySql某一列属性值为拼接时的查询方式
数据库中某一列的值为 使用IN查询是无法查询到数据的,只能查询到IN(2)或者IN(2,3) 查询结果: , style_id) 正确方式:使用FIND_IN_SET函数 , style_id) , ...
- how do I get the difference between two R named lists?
aa<- list(a=1, b="two", c=list(3, "four")) bb <- list(a=1, c=list(3, " ...
- postgreSql——时区问题
timestamptz.timestamp SELECT ts AT TIME ZONE 'UTC' FROM ( VALUES (timestamptz '2012-03-05 17:00:00+0 ...
- HDU 4557 Tree(可持久化字典树 + LCA)
http://acm.hdu.edu.cn/showproblem.php?pid=4757 题意: 给出一棵树,每个结点有一个权值,现在有多个询问,每次询问包含x,y,z三个数,求出在x到y的路径上 ...
- 前端面试总结 (转 0C°)
前端面试总结 1.一些开放性题目 1.自我介绍:除了基本个人信息以外,面试官更想听的是你与众不同的地方和你的优势. 2.项目介绍 3.如何看待前端开发? 4.平时是如何学习前端开发的? 5.未来三到五 ...
- 1. Mysql在java中的使用步骤
-1.配置数据库:http://www.cnblogs.com/sshoub/p/4321640.html 2.创建可以远程的登录用户:http://www.cnblogs.com/xyzdw/arc ...
- 【BZOJ】1831: [AHOI2008]逆序对
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1831 考虑$-1$的位置上填写的数字一定是不降的. 令${f[i][j]}$表示$DP$到 ...