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 ...
随机推荐
- 前端 --- 3 css 属性
一. 标签嵌套规则 块级标签能够嵌套某些块级标签和内敛标签(行内标签) 内敛标签不能嵌套块级标签,只能嵌套内敛标签 二. 属性 1.宽和高 (块级标签能够设置高度和宽度 内敛标签不能设置,设置了没 ...
- checkbox勾选事件,JQ设置css,下拉框JQ选中
<input id="CheckMainCompany" type="checkbox"/> $(function() { $("#Che ...
- Python 实用技巧
模块相关 导入模块时,可以通过模块的 __file__ 属性查看模块所在磁盘的路径位置,参考:关于Python包和模块的10个知识清单 Pip 安装Pip 方法一: sudo apt-get purg ...
- P2042 [NOI2005]维护数列
思路 超级恶心的pushdown 昏天黑地的调 让我想起了我那前几个月的线段树2 错误 这恶心的一道题终于过了 太多错误,简直说不过来 pushup pushdown 主要就是这俩不太清晰,乱push ...
- Docker 使用Dockerfile构建redis镜像
Dockerfile实现: FROM centos: MAINTAINER hongdada "hongdaqi159505@gmail.com" WORKDIR /home RU ...
- 【基本知识】Flume基本环境搭建以及原理
系统:CentOS6.5JDK:1.8.0_144Flume:flume-ng-1.6.0-cdh5.12.0 一.什么是Flume flume 作为 cloudera 开发的实时日志收集系统,受到了 ...
- JS获取节点的兄弟,父级,子级元素
https://blog.csdn.net/duanshuyong/article/details/7562423 先说一下JS的获取方法,其要比JQUERY的方法麻烦很多,后面以JQUERY的方法作 ...
- (转)看穿机器学习(W-GAN模型)的黑箱
本文转自:http://www.360doc.com/content/17/0212/11/35919193_628410589.shtml# 看穿机器学习(W-GAN模型)的黑箱 201 ...
- Druid介绍2
Druid的发送数据和查询数据 Druid 开篇 - 大数据实时探索性分析平台 官网 Druid 一次海量数据实时处理的实践 使用HDFS作为Druid的deepStorage 在哪里下载druid ...
- PTA 7-2 二叉搜索树的结构(30 分)
7-2 二叉搜索树的结构(30 分) 二叉搜索树或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值:若它的右子树不空,则右子树上所有结点的值均大 ...