Description

Farmer John has a problem: the dirt road from his farm to town has suffered in the recent rainstorms and now contains (1 <= N <= 10,000) mud pools. 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.

    牧场里下了一场暴雨,泥泞道路上出现了许多水坑,约翰想用一批长度为L的木板将这些水坑盖住.    牧场里的道路可以看成一根数轴,每个水坑可以用数轴上的两个坐标表示,如(3,6)表示从3到6有一个长度为3的水坑.所有的水坑都是不重叠的,(3,6)和(6,9)可以出现在同一个输入数据中,因为它们是两个连续的水坑,但不重叠.
    请你帮助约翰计算最少要用多少块木板才能将所有水坑盖住

Input

* Line 1: Two space-separated integers: N and L * 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.

    第1行有二个用空格隔开的整数N和L.其中1≤N≤10000,表示水坑总数.L为木板长度.
接下来的N行每行有二个用整数si和ei(0≤si<ei≤109),表示一个水坑的两个坐标.

Output

* Line 1: The miminum number of planks FJ needs to use.

 
    一个整数,表示约翰盖住所有水坑最少要用多少块长为L的木板.

Sample Input

3 3
1 6
13 17
8 12

Sample Output

5

HINT

sb模拟题

用pair<int,int>写的……感觉骚的没朋友

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,m,l,ans;
pa a[10010];
int main()
{
n=read();m=read();
for (int i=1;i<=n;i++)
{
a[i].first=read();
a[i].second=read()-1;
}
sort(a+1,a+n+1);
for (int i=1;i<=n;i++)
{
l=max(l,a[i].first-1);
int len=a[i].second-a[i].first;
ans+=len/m;
l+=(len/m)*m;
while (l<a[i].second)l+=m,ans++;
}
printf("%d\n",ans);
}

  

bzoj1689 [Usaco2005 Open] Muddy roads 泥泞的路的更多相关文章

  1. bzoj1689 / P1589 [Usaco2005 Open] Muddy roads 泥泞的路

    P1589 [Usaco2005 Open] Muddy roads 泥泞的路 简单的模拟题. 给水坑排个序,蓝后贪心放板子. 注意边界细节. #include<iostream> #in ...

  2. bzoj 1689: [Usaco2005 Open] Muddy roads 泥泞的路

    1689: [Usaco2005 Open] Muddy roads 泥泞的路 Description Farmer John has a problem: the dirt road from hi ...

  3. 【BZOJ】1689: [Usaco2005 Open] Muddy roads 泥泞的路(贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1689 一开始我也想到了贪心,,,策略是如果两个连续的水池的距离小于l的话,那么就将他们链接起来,,, ...

  4. P1689: [Usaco2005 Open] Muddy roads 泥泞的路

    水题,模拟就行了,别忘了L>=r的时候直接更新下一个的L然后continue type node=record l,r:longint; end; var n,l,i,ans:longint; ...

  5. bzoj 1689: [Usaco2005 Open] Muddy roads 泥泞的路【贪心】

    按左端点排序,贪心的选即可 #include<iostream> #include<cstdio> #include<algorithm> using namesp ...

  6. BZOJ1689: [Usaco2005 Open] Muddy roads

    1689: [Usaco2005 Open] Muddy roads Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 147  Solved: 107[Su ...

  7. bzoj 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 最小点覆盖

    链接 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 思路 这就是个上一篇的稍微麻烦版(是变脸版,其实没麻烦) 用边长为1的模板覆盖地图上的没有长草的土地,不能覆盖草地 ...

  8. BZOJ 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场

    Description 大雨侵袭了奶牛们的牧场.牧场是一个R * C的矩形,其中1≤R,C≤50.大雨将没有长草的土地弄得泥泞不堪,可是小心的奶牛们不想在吃草的时候弄脏她们的蹄子.  为了防止她们的蹄 ...

  9. [Usaco2005 Jan]Muddy Fields泥泞的牧场

    Description 雨连续不断的击打了放牛的牧场,一个R行C列的格子(1<=R<=50,1<=C<=50).虽然这对草来说是件好事,但这却使得一些没有草遮盖的土地变得很泥泞 ...

随机推荐

  1. docker初步

    [Note,]由于docker的局限性,docker只能运行在64位的系统中 docker软件应用程序可以重复地运行在任何地方,因为它的容器包含了所有的环境依赖关系! docker有三种方式运行 作为 ...

  2. Java迭代器深入理解及使用

    Iterator(迭代器) 作为一种设计模式,迭代器可以用于遍历一个对象,对于这个对象的底层结构开发人员不必去了解. java中的Iterator一般称为“轻量级”对象,创建它的代价是比较小的.这里笔 ...

  3. BZOJ 4541 【HNOI2016】 矿区

    题目链接:矿区 这道题去年暑假就想写了,但是一直拖拉,以至于现在才来写这道题.以前一直在刻意回避几何类的题目,但到了现在这个时候,已经没有什么好害怕的了. 正巧今天神犇\(xzy\)讲了这道题,那我就 ...

  4. [Immutable.js] Exploring Sequences and Range() in Immutable.js

    Understanding Immutable.js's Map() and List() structures will likely take you as far as you want to ...

  5. Gstreamer的一些基本概念与A/V同步分析

    一.媒体流(streams )流线程中包含事件和缓存如下:-events     -NEW_SEGMENT    (NS)     -EOS                (EOS)  *     - ...

  6. 【问题备注】VS2012不能输入代码,文字…

    第一次遇到,非常奇怪,一个项目,VS2012能正常打开,但是不能输入代码. 对比分析发现,其他项目能正常work.在于一个问题就是,VS2012 右下角有个INS一直在转一直analyzing,而正常 ...

  7. C#邮件发送

    public static void CreateCopyMessage() { MailAddress from = new MailAddress("yang@163.com" ...

  8. Android 加速Gradle构建项目

    1. 升级gradle 进入项目文件夹$project/gradle/wrapper/gradle-wrapper.properties, 使用最新的gradle. 修改替换为最新的 distribu ...

  9. jsp文件上传

    整理了一下jsp的上传下载,由客户端到服务端,包括一些常规的业务 一客户端 先看最基本的情况 1 在表单设置multipart/form-data,通过提交键把数据和附件一次性提交的.服务器更多的是对 ...

  10. 0122——UITabBarController

    UITabBarController是IOS中很常用的一个viewController.UITabBarController通常作为整个程序的rootViewController,而且不能添加到别的c ...