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 ...
随机推荐
- 使用SimpleDateFormat时的日期和时间模式
日期和时间模式 日期和时间格式由日期和时间模式 字符串指定.在日期和时间模式字符串中,未加引号的字母 ‘A’ 到’Z’ 和’a’ 到’z’ 被解释为模式字母,用来表示日期或时间字符串元素.文本可以使用 ...
- centos7之安装wordpress
wordpress安装教程如下: mysql安装可以参考我的博客园Centos构建Java环境:https://www.cnblogs.com/youcong/p/9118753.html 1.安装a ...
- Bootstrap3基础 clearfix pull-left/right 辅助类样式 快速左右浮动
内容 参数 OS Windows 10 x64 browser Firefox 65.0.2 framework Bootstrap 3.3.7 editor ...
- 自动化测试系列:Selenium UI自动化解决iframe定位问题
更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢! 原文链接:http://www.cnblogs.com/zishi/p/6735116.html 一个阴雨霏霏 ...
- How to know the directory size in CENTOS 查看文件夹大小
Under any linux system, you want to use the command du. (Disk Usage) Common usage is : du -sh file(s ...
- Symbol在对象中的作用
Symbol的打印 我们先声明一个Symbol,然后我们在控制台输出一下. var g = Symbol('jspang'); console.log(g); console.log(g.toStri ...
- 5、lvs使用进阶(01)
四层.七层负载均衡的区别 https://jaminzhang.github.io/lb/L4-L7-Load-Balancer-Difference/ netfilter/iptables简介 ...
- 2、zabbix工作原理及安装配置
Zabbix架构:zabbix基本术语.zabbix安装.配置和应用 Zabbix架构中的组件: zabbix-server:C语言 zabbix-server和zabbix-agent通过 ...
- 【译】第14节---数据注解-MaxLength/MinLength
原文:http://www.entityframeworktutorial.net/code-first/maxlength-minlength-dataannotations-attribute-i ...
- HDU 6212 Zuma(区间dp)
http://acm.hdu.edu.cn/showproblem.php?pid=6212 题意:有一行的祖玛,只由1和0组成,每次出现连续三个及以上的就会消去,问你最少需要发射多少个球才能消完. ...