P1589 [Usaco2005 Open] Muddy roads 泥泞的路

简单的模拟题。

给水坑排个序,蓝后贪心放板子。

注意边界细节。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct data{int l,r;}a[];
bool cmp(const data &A,const data &B){
return A.l<B.l||(A.l==B.l&&A.r>B.r);
}
int n,L,tl=-,ans;
int main(){
scanf("%d%d",&n,&L);
for(int i=;i<=n;++i)
scanf("%d%d",&a[i].l,&a[i].r);
sort(a+,a+n+,cmp);
for(int i=,q;i<=n;++i){
--a[i].r;
if(a[i].r<=tl) continue;
if(tl<a[i].l){
q=(a[i].r-a[i].l)/L;
ans+=q; tl=a[i].l-+q*L;
if(tl<a[i].r) ++ans,tl+=L;
}else if(tl<a[i].r){
q=(a[i].r-tl)/L;
ans+=q; tl+=q*L;
if(tl<a[i].r) ++ans,tl+=L;
}
}printf("%d",ans);
return ;
}

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

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

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

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

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

  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. Deplearning.AI-吴恩达【中文课后作业】

    [吴恩达课后作业目录] 课程 周数 名称 类型 语言 地址 课程1 - 神经网络和深度学习 第1周 深度学习简介 测验 中英 传送门 无编程作业 编程作业 —— —— 第2周 神经网络基础 测验 中英 ...

  2. 查询ip

    ifconfig | grep "inet " | grep -v 127.0.0.1

  3. 2018牛客网暑期ACM多校训练营(第三场) H - Diff-prime Pairs - [欧拉筛法求素数]

    题目链接:https://www.nowcoder.com/acm/contest/141/H 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K ...

  4. codeforces 761D - Dasha and Very Difficult Problem

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  5. LightOJ 1030 - Discovering Gold - [概率DP]

    题目链接:https://cn.vjudge.net/problem/LightOJ-1030 You are in a cave, a long cave! The cave can be repr ...

  6. SQL Fundamentals || DCL(Data Control Language) || 系统权限&对象权限管理(GRANT&REVOKE)

    SQL Fundamentals || Oracle SQL语言 语句 解释 Create user Creates a user(usually performed by a DBA) Grant ...

  7. Django的quarySet

    models.py 代码 from django.db import models # Create your models here. class Author(models.Model): nam ...

  8. 数据结构——栈(C语言实现)

    #include <stdio.h> #include <stdlib.h> #include<string.h> #include<malloc.h> ...

  9. gulp-webserver

    gulp-webserver是开启服务器,通常和gulp-livereload结合使用.而这两个结合使用效果,几乎类似browser-Sync.下面是gulp-webserver和gulp-liver ...

  10. python count()

    count() 描述 Python count() 方法用于统计字符串里某个字符出现的次数.可选参数为在字符串搜索的开始与结束位置. 语法 count()方法语法: str.count(sub, st ...