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. heritrix 3.2.0 下载

    由于archive.org屏蔽,编译完成版本 http://builds.archive.org/maven2/org/archive/heritrix/heritrix/3.2.0/ 无法下载. 现 ...

  2. bzoj3393 [Usaco2009 Jan]Laserphones 激光通讯

    Description Input 第1行输入w和H,之后W行H列输入地图,图上符号意义如题目描述. Output 最少的对角镜数量. Sample Input 7 8 ....... ...... ...

  3. Hive 2、Hive 的安装配置(本地MySql模式)

    一.前提条件 安装了Zookeeper.Hadoop HDFS HA  安装方法: http://www.cnblogs.com/raphael5200/p/5154325.html 二.安装Mysq ...

  4. RMAN-使用catalog恢复目录进行备份与恢复

    RMAN ArchitectureThe RMAN architecture, shown in Figure 7-3, includes a target database, repository, ...

  5. [HeadFirst-HTMLCSS学习笔记][第十四章交互活动]

    表单 <form action="http://wickedlysmart.com/hfhtmlcss/contest.php" method="POST" ...

  6. RS-232通信原理

    rs232串口通信原理 串口是计算机上一种非常通用设备通信的协议(不要与通用串行总线Universal Serial Bus或者USB混淆).大多数计算机包含两个基于RS232的串口.串口同时也是仪器 ...

  7. 提示框的优化之自定义Toast组件之(二)Toast组件的业务逻辑实现

    在java下org.socrates.mydiary.activity下LoginActivity下自定义一个方法showCustomerToast()  public class LoginAct ...

  8. oracle 语句汇总

    Oracle数据库常用sql语句 ORACLE 常用的SQL语法和数据对象 一.数据控制语句 (DML) 部分 1.INSERT  (往数据表里插入记录的语句) INSERT INTO 表名(字段名1 ...

  9. 值栈和OGNL 之 7.1 值栈

    7.1  值栈 7.1.1  值栈是什么 简单的说:值栈是对应每一个请求对象的轻量级的内存数据中心. Struts2中一个很激动人心的特性就是引入了值栈,在这里统一管理着数据,供Action.Resu ...

  10. 已知TSP问题的最好解

    a280 : 2579ali535 : 202339att48 : 10628att532 : 27686bayg29 : 1610bays29 : 2020berlin52 : 7542bier12 ...