题目链接:https://vjudge.net/contest/194475#problem/C

题目大意:

有n滩泥 木板长度为L 求至少需要多少木板才能覆盖这些泥

解题思路:

把泥块的起点升序排序,分三种情况讨论
1、前一个木板完全覆盖了当前的泥 跳过
2、前一个木板覆盖了一部分 则计算铺完剩下的泥需要多少木板
3、前一个木板完全没接触到当前的木板 则更新端点
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define MAXN 10000+100
typedef struct
{
int s, e;
}node;
node a[MAXN];
bool cmp(node a, node b)
{
return a.s < b.s;
}
int main()
{
int n, l;
scanf("%d %d", &n, &l);
for (int i = ; i < n; i++)
scanf("%d %d", &a[i].s, &a[i].e);
sort(a, a + n, cmp);
int ans = ;
int last = -;
for (int i = ; i < n; i++)
{
if (last >= a[i].e)
continue;
if (last > a[i].s)
{
int num = ceil((a[i].e - last)*1.0 / l); //向上取整函数
last += num * l;
ans += num;
}
else
{
int num = ceil((a[i].e - a[i].s)*1.0/l);
last = a[i].s + num * l;
ans += num;
}
}
printf("%d\n", ans);
return ;
}

2018-04-21

POJ 2437 Muddy roads【贪心】(区间覆盖)的更多相关文章

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

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

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

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

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

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

  4. 南阳OJ-12-喷水装置(二)贪心+区间覆盖

    题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=12 题目大意: 有一块草坪,横向长w,纵向长为h,在它的橫向中心线上不同位置处装有 ...

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. MySQL事务隔离级别以及验证

    事务的并发执行,容易出现的几个现象 --------------------------     1.脏读         读未提交,一个事务读取了另外一个事务改写还没有提交的数据,如果另外一个    ...

  2. A - A Secret (扩展kmp)

    题目链接:https://cn.vjudge.net/contest/283743#problem/A 题目大意:给你字符串s1和s2,然后问你s2的每一个后缀在s1中出现的次数之和(可重叠). 具体 ...

  3. 课程2:《黑马程序员_Java基础视频-深入浅出精华版》-视频列表-

    \day01\avi\01.01_计算机基础(计算机概述).avi; \day01\avi\01.02_计算机基础(计算机硬件和软件概述).avi; \day01\avi\01.03_计算机基础(软件 ...

  4. CentOS和RedHat Linux的区别

    RHEL 在发行的时候,有两种方式.一种是二进制的发行方式,另外一种是源代码的发行方式. 无论是哪一种发行方式,你都可以免费获得(例如从网上下载),并再次发布.但如果你使用了他们的在线升级(包括补丁) ...

  5. 【windows核心编程】注入DLL时BUG排除与调试

    DLL注入排除bug的思路步骤. 1.在VS中监视输入err,hr检查DLL是否注入成功 2.OD断点loadlibraryW,loadlibraryA是否已经注入成功,eax是否有值. 3.检查路径 ...

  6. SpringMVC中fastjson支持jsonp的实现

    前边一篇文章主要说了下前端处理jsonp的方式,这篇主要介绍了后台接收和响应jsonp的一种方式 继承fastjson消息转换器类:com.alibaba.fastjson.support.sprin ...

  7. mysql通过centos本地命令行还原数据库出现乱码问题

    将sql文件上传到centos系统中,还原mysql数据库,发现是乱码 mysql -h10.11.8.62 -uroot -p dbtest </data/dbsql/dbtest.sql 数 ...

  8. unicode-range特定字符使用font-face自定义字体

    链接: https://www.zhangxinxu.com/wordpress/2016/11/css-unicode-range-character-font-face/

  9. EntityFramework codefirst Enable-Migrations No context type was found in the assembly “MyApp.Web” error

    Enable-Migrations -Force -ContextTypeName "MyApp.Repository.DataContext" -ProjectName &quo ...

  10. mockito简单教程

    注:本文来源:sdyy321的<mockito简单教程> 官网: http://mockito.org API文档:http://docs.mockito.googlecode.com/h ...