POJ2437 Muddy roads
Description
Farmer John has a collection of wooden planks of length L that he can use to bridge these mud pools. He can overlap planks and the ends do not need to be anchored on the ground. However, he must cover each pool completely.
Given the mud pools, help FJ figure out the minimum number of planks he needs in order to completely cover all the mud pools.
Input
* Lines 2..N+1: Line i+1 contains two space-separated integers: s_i and e_i (0 <= s_i < e_i <= 1,000,000,000) that specify the start and end points of a mud pool along the road. The mud pools will not overlap. These numbers specify points, so a mud pool from 35 to 39 can be covered by a single board of length 4. Mud pools at (3,6) and (6,9) are not considered to overlap.
Output
Sample Input
3 3
1 6
13 17
8 12
Sample Output
5
Hint
FJ needs to use planks of length 3 to cover 3 mud pools. The mud pools cover regions 1 to 6, 8 to 12, and 13 to 17.
OUTPUT DETAILS:
FJ can cover the mud pools with five planks of length 3 in the following way:
111222..333444555....
.MMMMM..MMMM.MMMM....
012345678901234567890
Source
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const int mxn=;
struct wd{
int x,y;
bool operator < (const wd rhd){
return x<rhd.x;
}
}a[mxn];
int n,L;
int main(){
scanf("%d%d",&n,&L);
int i,j;
for(i=;i<=n;i++){
scanf("%d%d",&a[i].x,&a[i].y);
}
sort(a+,a+n+);
int cnt=;
int now=;
for(i=;i<=n;i++){
now=max(now,a[i].x);//开始铺
while(now<a[i].y){
now+=L;
cnt++;
}
}
printf("%d\n",cnt);
return ;
}
POJ2437 Muddy roads的更多相关文章
- BZOJ1689: [Usaco2005 Open] Muddy roads
1689: [Usaco2005 Open] Muddy roads Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 147 Solved: 107[Su ...
- bzoj1689 / P1589 [Usaco2005 Open] Muddy roads 泥泞的路
P1589 [Usaco2005 Open] Muddy roads 泥泞的路 简单的模拟题. 给水坑排个序,蓝后贪心放板子. 注意边界细节. #include<iostream> #in ...
- bzoj 1689: [Usaco2005 Open] Muddy roads 泥泞的路
1689: [Usaco2005 Open] Muddy roads 泥泞的路 Description Farmer John has a problem: the dirt road from hi ...
- P1689: [Usaco2005 Open] Muddy roads 泥泞的路
水题,模拟就行了,别忘了L>=r的时候直接更新下一个的L然后continue type node=record l,r:longint; end; var n,l,i,ans:longint; ...
- bzoj1689 [Usaco2005 Open] Muddy roads 泥泞的路
Description Farmer John has a problem: the dirt road from his farm to town has suffered in the recen ...
- POJ 2437 Muddy roads【贪心】(区间覆盖)
题目链接:https://vjudge.net/contest/194475#problem/C 题目大意: 有n滩泥 木板长度为L 求至少需要多少木板才能覆盖这些泥 解题思路: 把泥块的起点升序排序 ...
- 【BZOJ】1689: [Usaco2005 Open] Muddy roads 泥泞的路(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1689 一开始我也想到了贪心,,,策略是如果两个连续的水池的距离小于l的话,那么就将他们链接起来,,, ...
- bzoj 1689: [Usaco2005 Open] Muddy roads 泥泞的路【贪心】
按左端点排序,贪心的选即可 #include<iostream> #include<cstdio> #include<algorithm> using namesp ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
随机推荐
- Javascript中call和apply的区别与详解
在js中call和apply它们的作用都是将函数绑定到另外一个对象上去运行,两者仅在定义参数方式有所区别,下面我来给大家介绍一下call和apply用法: 在web前端开发过程中,我们经常需要改变th ...
- c# 二进制或算法实现枚举的HasFlag函数
from:http://www.cnblogs.com/icyJ/archive/2013/02/20/HasFlag.html 在权限的管理中,常常会出现一个权限包含的现象.例如,有三种基本权限:职 ...
- 4201 TortoiseSVN常用配置
在Windows下推荐使用乌龟(Tortoise)SVN客户端. TortoiseSVN 是 Subversion 版本控制系统的一个免费开源客户端,可以超越时间的管理文件和目录.文件保存在中央版本库 ...
- C#泛型-模板特化
class TClass<T, K> { } class SubTClass<T, C, K> : TClass<Char, K> { } class SubTCl ...
- Asp.net设计模式笔记之二:应用程序分离与关注点分离
本次笔记主要涉及的内容如下: 1.将智能UI(SmartUI)反模式重构成分层方式的示例代码 2.分层设计与传统的Asp.net WebForm模型(代码后植)相比具有的优势 3.逻辑分层概念以及分离 ...
- [Android] 【视频】黑马安卓62、66期等教程+源码
下载地址:http://fu83.cn/thread-58-1-1.html
- LeetCode:Path Sum I II
LeetCode:Path Sum Given a binary tree and a sum, determine if the tree has a root-to-leaf path such ...
- 信息安全系统设计基础实验一:Linux开发环境的配置和使用
北京电子科技学院(BESTI) 实验报告 课程:信息安全系统设计基础 班级:1353 姓名:芦畅 傅冬菁 学号:20135308 20135311 成绩: 指导教师:娄家鹏 ...
- 浪潮之巅——IT那点事之二—蓝色巨人IBM
蓝色巨人IBM的全称是国际商用机器公司(International Business Machines Corporation),纵观IBM的发展历史,可以看出IBM与机器结缘,以商用为主的发展策略. ...
- 安装.NET CORE
需要安装两个包 https://github.com/dotnet/cli 1. .NET Core Installer 2. .NET Core SDK Installer