题目链接:

http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=12

题目大意:

有一块草坪,横向长w,纵向长为h,在它的橫向中心线上不同位置处装有n(n<=10000)个点状的喷水装置,每个喷水装置i喷水的效果是让以它为中心半径为Ri的圆都被润湿。请在给出的喷水装置中选择尽量少的喷水装置,把整个草坪全部润湿。

传送门:喷水装置(一)

思路:

区间覆盖问题,每个点有一段喷水区间,按照左端点排序即可,设置两变量begin, end,依次扫过去,每次取覆盖begin的区间更新end,如果没能覆盖begin,说明已经到了当前的最右端,begin=end,再次扫描,如果每次扫描开始的时候就不能覆盖begin,则无解,如果每次扫描的时候没有找到合适的end,也无解。如果最终的begin<l也表示到达不了终点。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = 1e4 + ;
int T, n;double l, w;
struct node
{
double x, y;
bool operator < (const node a)const
{
return x < a.x;
}
node(){}
node(double x, double y):x(x), y(y){}
};
node a[maxn];
int main()
{
cin >> T;
while(T--)
{
cin >> n >> l >> w;
w = w * 0.5;
int tot = ;
double x, r;
for(int i = ; i < n; i++)
{
cin >> x >> r;
if(r <= w)continue;
double c = sqrt(1.0 * r * r - w * w);
a[tot].x = 1.0 * x - c;
a[tot++].y = 1.0 * x + c;
if(a[tot - ].x > l || a[tot - ].y < )tot--;
}
sort(a, a + tot);
double begin = , end = -;
int ans = ;
for(int i = ; i < tot && begin < l;)
{
if(a[i].x > begin)
{
ans = ;
break;
}
while(i < tot && a[i].x <= begin)//覆盖begin的区间更新出最大的end
{
end = max(end, a[i].y);
i++;
}
if(end < )//说明没有找到合适的区间,直接无解
{
ans = ;
break;
}
ans++;
begin = end;//更新两者
end = -;
}
if(begin < l)ans = ;
cout<<ans<<endl;
}
return ;
}

南阳OJ-12-喷水装置(二)贪心+区间覆盖的更多相关文章

  1. 高效算法——E - 贪心-- 区间覆盖

    E - 贪心-- 区间覆盖 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/E 解题思路: 贪心思想, ...

  2. 【题解】Cut the Sequence(贪心区间覆盖)

    [题解]Cut the Sequence(贪心区间覆盖) POJ - 3017 题意: 给定一大堆线段,问用这些线段覆盖一个连续区间1-x的最小使用线段的数量. 题解 考虑一个这样的贪心: 先按照左端 ...

  3. nyoj 12——喷水装置二——————【贪心-区间覆盖】

    喷水装置(二) 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 有一块草坪,横向长w,纵向长为h,在它的橫向中心线上不同位置处装有n(n<=10000)个点状的 ...

  4. UVA 10382 - Watering Grass【贪心+区间覆盖问题+高精度】

    UVa 10382 - Watering Grass n sprinklers are installed in a horizontal strip of grass l meters long a ...

  5. 51nod 1091 线段的重叠【贪心/区间覆盖类】

    1091 线段的重叠 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题  收藏  关注 X轴上有N条线段,每条线段包括1个起点和终点.线段的重叠是这样来算的,[10 2 ...

  6. UVA 10382 Watering Grass 贪心+区间覆盖问题

    n sprinklers are installed in a horizontal strip of grass l meters long and w meters wide. Each spri ...

  7. B. Heaters 思维题 贪心 区间覆盖

    B. Heaters 这个题目虽然只有1500的分数,但是我还是感觉挺思维的,我今天没有写出来,然后看了一下题解 很少做这种区间覆盖的题目,也不是很擅长,接下来讲讲我看完题解后的思路. 题目大意是:给 ...

  8. UVA 10020 Minimal coverage(贪心 + 区间覆盖问题)

     Minimal coverage  The Problem Given several segments of line (int the X axis) with coordinates [Li, ...

  9. hdoj 4883 TIANKENG’s restaurant【贪心区间覆盖】

    TIANKENG’s restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/O ...

随机推荐

  1. 笔记:Spring Cloud Hystrix Command属性

    主要用来控制 HystrixCommand 命令的行为,主要有下面5种类型的属性配置: execution配置 该配置前缀为 hystrix.command.default execution.iso ...

  2. linux内核管理

      一  linux组成:kernel.库.rootfs.程序 1.kernel的功能: 1) kernel提供的功能都通过系统调用给用户接口 2) kernel包括:进程管理 .内存管理 .网络管理 ...

  3. MYSQL数据库学习十三 使用MySQL常用函数

    13.1 字符串函数 对于针对字符串位置的操作,第一个位置被标记为1. 函数 功能 CONCAT(str1,str2...strn) 连接字符串str1.str2....strn INSERT(str ...

  4. HDU4310HERO贪心问题

    问题描述 When playing DotA with god-like rivals and pig-like team members, you have to face an embarrass ...

  5. Java实现单向链表反转

    public class LinkedListTest { public static void main(String[] args) { Node A = new Node("A&quo ...

  6. 基于jquery的插件开发

    最近在公司做一个项目,由于后台数据太多需要分页显示,在网上找了很多插件都没有找到合适的分页插件,所有的分页插件始终达不到自己想要的效果.由于这个项目也不是很赶,就在网上查找各种资料,自己写一个基于jq ...

  7. Find The Multiply

    Find The Multiply poj-1426 题目大意:给你一个正整数n,求任意一个正整数m,使得n|m且m在十进制下的每一位都是0或1. 注释:n<=200. 想法:看网上的题解全是b ...

  8. vue 2.0之基础

    Vue Vue实例 创建实例: var vm = new Vue({ //code }) 数据与方法: 只有当实例被创建时 data 中存在的属性才是响应式的; Vm.b = 'h1' 是不会触发视图 ...

  9. python全栈学习--day4

    列表 说明:列表是python中的基础数据类型之一,它是以[]括起来,每个元素以逗号隔开,而且他里面可以存放各种数据类型比如:   1 li = ['alex',123,Ture,(1,2,3,'wu ...

  10. 论文阅读——Visual inertial odometry using coupled nonlinear optimization

    简介:论文提出一种新的视觉里程计算法,其直接利用带噪声的IMU数据和视觉特征位置来优化相机位姿.不同于对IMU和视觉数据运行分离的滤波器,这种算法将它们纳入联合的非线性优化框架中.视觉特征的透视重投影 ...