UVa 10382 - Watering Grass 贪心,水题,爆int 难度: 0
题目
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1323
题意
长方形l * w,给出长方形中间那条线上n个圆的圆心c和半径r,选取最少数目的圆覆盖长方形,选不了输出-1
思路
明显,算出圆在边上的坐标,然后尽量从左向右扩展就行
感想:
卡题的原因是反射性以为r和w很小,但其实可以很大,所以用double存r
代码
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#define LOCAL_DEBUG
using namespace std;
typedef pair<double, double> MyPair;
const int MAXN = 1e4 + ;
double c[MAXN];
double r[MAXN];
MyPair myRange[MAXN];
double posmx[MAXN]; int main() {
#ifdef LOCAL_DEBUG
freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\input.txt", "r", stdin);
//freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\output.txt", "w", stdout);
#endif // LOCAL_DEBUG
int T;
int n, l, w;
for (int ti = ;cin>>n>>l>>w; ti++) {
for (int i = ; i < n; i++) {
cin >> c[i] >> r[i];
double gap = (r[i] >= (w / 2.0) ? sqrt(r[i] * r[i] - w * w / 4.0) : -);
myRange[i] = MyPair(c[i] - gap, c[i] + gap);
}
sort(myRange, myRange + n);
bool fl = myRange[].first <= ;
double pos = ;
int ans = ;
for (int i = ; i < n && fl && pos < l; ans++) {
double posNxt = -;
while (i < n && myRange[i].first <= pos) {
posNxt = max(posNxt, myRange[i].second);
i++;
}
if (posNxt <= pos && pos < l) { fl = false; }
else pos = posNxt;
}
if (!fl || pos < l)ans = -;
printf("%d\n", ans);
} return ;
}
UVa 10382 - Watering Grass 贪心,水题,爆int 难度: 0的更多相关文章
- 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【贪心+区间覆盖问题+高精度】
UVa 10382 - Watering Grass n sprinklers are installed in a horizontal strip of grass l meters long a ...
- UVA 10382 Watering Grass(区间覆盖,贪心)题解
题意:有一块草坪,这块草坪长l 米,宽 w 米,草坪有一些喷头,每个喷头在横坐标为 p 处,每个喷头的纵坐标都是(w/2) ,并且喷头的洒水范围是一个以喷头为圆心,半径为 r 米的圆.每次最少需要打开 ...
- UVa 10382 Watering Grass (区间覆盖贪心问题+数学)
题意:有一块长为l,宽为w的草地,在其中心线有n个喷水装置,每个装置可喷出以p为中心以r为半径的圆, 选择尽量少的装置,把草地全部润湿. 析:我个去啊,做的真恶心,看起来很简单,实际上有n多个坑啊,首 ...
- UVA 10382 Watering Grass (区间覆盖,贪心)
问题可以转化为草坪的边界被完全覆盖.这样一个圆形就换成一条线段. 贪心,从中选尽量少的线段把区间覆盖,按照把线段按左端点排序,记录一个当前已经覆盖区间的位置cur, 从左端点小于等于cur选一个右端点 ...
- 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
题目大意:有一条长为l,宽为w的草坪,在草坪上有n个洒水器,给出洒水器的位置和洒水半径,求能浇灌全部草坪范围的洒水器的最小个数. 经典贪心问题:区间覆盖.用计算几何对洒水器的覆盖范围简单处理一下即可得 ...
- uva 10382 - Watering Grass(区域覆盖问题)
Sample Input 8 20 2 5 3 4 1 1 2 7 2 10 2 13 3 16 2 19 4 3 10 1 3 5 9 3 6 1 3 10 1 5 3 1 1 9 1 Sample ...
- uva 10382 Watering Grass_贪心
题意:给你个矩形n*m,再给你n个圆的圆心坐标和半径,问最用最少用几个圆把这个矩形覆盖 思路:直接想发现这问题不容易,后来发现可以把圆看做区间(能把矩形面积覆盖),然后这个问题就容易解决了 #incl ...
随机推荐
- 《linux就该这么学》第十节课:第8章iptables和firewalld
网卡配置: 物理机:192.168.10.1/24 服务器:192.168.10.10/24 客户端:192.168.10.20/24 1.vim /etc/sysc ...
- linq 表分组后关联查询
测试linq,获取有教师名额的学校.比如学校有5个教师名额,teacher数量没超过5个,发现有空额 var query = (from teacher in _repositoryTeacher.T ...
- armv8 memory translation
AArch32,arm的32bit架构: AArch64,arm的64bit架构: ARMv8.2-LPA,是armv8.2中的新feature,扩大了IPA和PA的支持范围,从48bit扩展到52b ...
- C++对象赋值问题
- 自定义Word颜色主题
外观 说明 看到这个黑色编辑器的界面,第一印象可能认为是Sublime.Atom. VScode或者其它markdown编辑器.其实仅仅是微软的Word经过了自定义主题. 选择清晰易于辨认的字体和深色 ...
- mybites
[mybatis-spring] http://www.mybatis.org/spring/zh/index.html 使用spring mybatis 中间件 方便使用 mybatis [myba ...
- 1333:【例2-2】Blah数集
1333:[例2-2]Blah数集 注意是数组,答案数组中不能有重复数字 q数组是存储答案的 代码: #include<iostream> #include<cstdio> # ...
- Eclipse中XML文件自定义格式化配置
1,编码格式:UTF-8 2,Line Width:90,Indent using spaces:2 3,默认编辑器 当添加Spket插件后,xml文件默认编辑器将被修改为Spket,要求恢复默认,则 ...
- Celery 实现异步任务-one
celery异步任务: 环境准备 安装celery ,django-celery. 就是一个专注于实时处理和任务调度的分布式队列. 可以异步执行的任务交给后台处理,以防网络阻塞,减小响应时间 cele ...
- 在cef中使用自定义协议(scheme)
在谷歌浏览器中点击设置,地址栏里出现的不是普通网址,而是chrome://settings/ 这个地址就是谷歌浏览器的自定义scheme,cef也提供了自定义协议手段.主要是通过 以下几步: 1.继承 ...