UVA 10382 Watering Grass (区间覆盖,贪心)
问题可以转化为草坪的边界被完全覆盖。这样一个圆形就换成一条线段。
贪心,从中选尽量少的线段把区间覆盖,按照把线段按左端点排序,记录一个当前已经覆盖区间的位置cur,
从左端点小于等于cur选一个右端点最大的作为这次选的区间,如果没有符合条件的,说明不可能完全覆盖。
r*r会爆int...
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e4+;
int n,l,w;
struct seg
{
double l,r;
bool operator < (const seg& rh)const {
return l < rh.l;
}
}L[maxn]; int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d%d%d",&n,&l,&w)){
double d = w*w/.;
int ss = ;
for(int i = ; i < n; i++){
int p,r; scanf("%d%d",&p,&r);
if(*r<=w) {
continue;
}
double dx = sqrt(.*r*r-d);
L[ss].l = p-dx; L[ss++].r = p+dx;
}
sort(L,L+ss);
double cur = .; bool fg = false;
int ans = ; for(int i = ; i < ss;){
int j = i;
double nxt = cur;
while(j<ss && L[j].l <= cur) {
if(L[j].r > nxt) nxt = L[j].r;
j++;
}
if(j == i) break;
ans++;
cur = nxt;
i = j;
if(cur>=l){ fg = true; break; }
} if(fg) printf("%d\n",ans);
else puts("-1");
}
return ;
}
UVA 10382 Watering Grass (区间覆盖,贪心)的更多相关文章
- 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 贪心+区间覆盖问题
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 ...
- 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
题目大意:有一条长为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个圆.已知矩形的长宽和圆的半径,问最少需多少个圆将矩形完全覆盖. 分析: 1.首先求圆与矩形的长的交点,若无交点,则一定不能对用最少的圆覆盖矩形有贡献. 2.如果两个圆与矩形相交所 ...
随机推荐
- iwork 文件格式分析
根据维基百科,到2015年苹果推出的iwork版本 第一章:iwork2008介绍 1.文档结构: 是一个资源合集:压缩格式的(内含文件夹和文件) 在windows下修改iwork的文件后缀为.rar ...
- 软件工程作业——Word Counter
github地址 https://github.com/Pryriat/Word_Counter 项目说明 wc.exe 是一个常见的工具,它能统计文本文件的字符数.单词数和行数.这个项目要求写一个命 ...
- 浅淡Java多线程
工作中一直忙着实现业务逻辑,多线程接触得不多.对多线程的认知,一直停留在Thread和Runnable上.最近心血来潮,找了几本多线程的书,不看不知道,一看吓一跳.原来我对多线程的理解是多么的肤浅.记 ...
- java五行代码导出Excel
目录 先看代码 再看效果 EasyExcel 附: Java按模板导出Excel---基于Aspose实现 Java无模板导出Excel,Apache-POI插件实现 已经写过两种Excel导出插件了 ...
- React `controlled` 及 `uncontrolled` 组件
通过 props 来设置其 value 值的组件便是一种 controlled 组件.典型的 form 表单中,像 输入框 <input> 下拉框 <select> 多选框 & ...
- 使用tcpdump抓取EOS帐户创建与交易数据
基本环境配置 EOS 版本:1.0.1(2018-06-04更新) 节点nodeos http监听端口:127.0.0.1:8888 本地钱包keosd http监听端口:127.0.0.1:89 ...
- ==和equals方法
Java程序中测试两个变量时否相等有两种方法: == 和 equals. ==判断 当使用==来判断两个变量是否相等时,如果两个变量是基本类型变量,且都是数字类型(不一定要求数据类型严格相同),则只要 ...
- js异步加载和按需加载
function loadScript(url,callback){ var script = document.creatElement("script"); script.ty ...
- 10.使用子查询 ---SQL
利用子查询进行过滤 普通查询: SELECT order_num FROM OrderItems WHERE prod_id = 'RGAN01'; 输出▼ order_num ----------- ...
- svn安装到myeclipse 和客户端安装
https://jingyan.baidu.com/article/eae07827a977b61fed548572.html