1689: [Usaco2005 Open] Muddy roads

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 147  Solved: 107
[Submit][Status][Discuss]

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.

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. 有N个MUD,用长度为L的木块去Cover.问至少要多少块.

Output

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

Sample Input

3 3
1 6
13 17
8 12

INPUT DETAILS:

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.

Sample Output

5

OUTPUT DETAILS:

FJ can cover the mud pools with five planks of length 3 in the
following way:
111222..333444555....
.MMMMM..MMMM.MMMM....
012345678901234567890

HINT

 

Source

题解:
又是这样的题。。。
考虑边界,瞬间变水题。。。
第一个有泥泞的点一定需要作为 l 的左端点被覆盖一次,然后剩下的继续这样考虑。。。
代码:
 #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int n,L;
struct ken{int l,r;} a[];
bool kp(const ken &i,const ken &j) {return i.l<j.l;}
void init()
{
scanf("%d%d",&n,&L);
int i;
for(i=;i<=n;i++)
scanf("%d%d",&a[i].l,&a[i].r);
sort(a+,a+n+,kp);
}
void work()
{
int i,len=,w=,ans=;
for(i=;i<=n;i++)
{if(w>=a[i].r) continue;
w=max(a[i].l,w);
while(w<a[i].r) {ans++; w+=L;}
}
printf("%d\n",ans);
}
int main()
{
init(); work();
return ;
}

BZOJ1689: [Usaco2005 Open] Muddy roads的更多相关文章

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

    Description Farmer John has a problem: the dirt road from his farm to town has suffered in the recen ...

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

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

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

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

  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 泥泞的路(贪心)

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

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

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

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

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

  8. [USACO2005][POJ2226]Muddy Fields(二分图最小点覆盖)

    题目:http://poj.org/problem?id=2226 题意:给你一个字符矩阵,每个位置只能有"*"或者“.",连续的横着或者竖的“*"可以用一块木 ...

  9. POJ2437 Muddy roads

    Description Farmer John has a problem: the dirt road from his farm to town has suffered in the recen ...

随机推荐

  1. 使用strace查看C语言级别的php源码

    XCACHE XCache 是一个开源的 opcode 缓存器/优化器, 这意味着他能够提高您服务器上的 PHP 性能. 他通过把编译 PHP 后的数据缓冲到共享内存从而避免重复的编译过程, 能够直接 ...

  2. java--字节数组输入、输出流

    在java网络编程中,字节数组很重要,它可以传输任何资料(文本,音频,视频,图片等),因此掌握字节数组和其它数据类型的相互转化尤为重要. 示例代码: package com.lky.util; imp ...

  3. 判断IE版本的HTML语句详解<!--[if IE]> <![endif]--> - AnswerCard

    一个页面里面只能有一句这样的判断 我们常常会在网页的HTML里面看到形如[if lte IE 9]……[endif]的代码,表示的是限定某些浏览器版本才能执行的语句,那么这些判断语句的规则是什么呢?请 ...

  4. 控制uibutton的title范围

    moreBtn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 10);

  5. cocos2dx--cocos2dx3.1.1执行报无法解析的外部符号

    使用cocos2dx3.1.1和VS2012 新建了一个名为test的工程.放在D:\cocos2dx\cocos2d-x-3.1.1\projects下 编译通过,没问题 用cocostudio的场 ...

  6. [Redux] Implementing combineReducers() from Scratch

    The combineReducers function we used in previous post: const todoApp = combineReducers({ todos, visi ...

  7. boost::pool与内存池技术

      建议看这个链接的内容:http://cpp.winxgui.com/cn:mempool-example-boost-pool Pool分配是一种分配内存方法,用于快速分配同样大小的内存块,    ...

  8. Python之基础(一)

    数学计算 要利用相关的数学计算函数,首先需要把数学模块包含进来: >>>import math 进行计算: >>> math.pi 3.14159265358979 ...

  9. Senparc.Weixin.MP SDK 微信公众平台开发教程 索引

    Senparc.Weixin.MP SDK从一开始就坚持开源的状态,这个过程中得到了许多朋友的认可和支持. 目前SDK已经达到比较稳定的版本,这个过程中我觉得有必要整理一些思路和经验,和大家一起分享. ...

  10. 学习Android MediaPlayer

    Android Media Playback 原文 The Android multimedia framework includes support for playing variety of c ...