bzoj1689 / P1589 [Usaco2005 Open] Muddy roads 泥泞的路
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 泥泞的路的更多相关文章
- bzoj 1689: [Usaco2005 Open] Muddy roads 泥泞的路
1689: [Usaco2005 Open] Muddy roads 泥泞的路 Description Farmer John has a problem: the dirt road from hi ...
- bzoj1689 [Usaco2005 Open] Muddy roads 泥泞的路
Description Farmer John has a problem: the dirt road from his farm to town has suffered in the recen ...
- 【BZOJ】1689: [Usaco2005 Open] Muddy roads 泥泞的路(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1689 一开始我也想到了贪心,,,策略是如果两个连续的水池的距离小于l的话,那么就将他们链接起来,,, ...
- P1689: [Usaco2005 Open] Muddy roads 泥泞的路
水题,模拟就行了,别忘了L>=r的时候直接更新下一个的L然后continue type node=record l,r:longint; end; var n,l,i,ans:longint; ...
- bzoj 1689: [Usaco2005 Open] Muddy roads 泥泞的路【贪心】
按左端点排序,贪心的选即可 #include<iostream> #include<cstdio> #include<algorithm> using namesp ...
- BZOJ1689: [Usaco2005 Open] Muddy roads
1689: [Usaco2005 Open] Muddy roads Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 147 Solved: 107[Su ...
- bzoj 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 最小点覆盖
链接 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 思路 这就是个上一篇的稍微麻烦版(是变脸版,其实没麻烦) 用边长为1的模板覆盖地图上的没有长草的土地,不能覆盖草地 ...
- BZOJ 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场
Description 大雨侵袭了奶牛们的牧场.牧场是一个R * C的矩形,其中1≤R,C≤50.大雨将没有长草的土地弄得泥泞不堪,可是小心的奶牛们不想在吃草的时候弄脏她们的蹄子. 为了防止她们的蹄 ...
- [Usaco2005 Jan]Muddy Fields泥泞的牧场
Description 雨连续不断的击打了放牛的牧场,一个R行C列的格子(1<=R<=50,1<=C<=50).虽然这对草来说是件好事,但这却使得一些没有草遮盖的土地变得很泥泞 ...
随机推荐
- Linux下搭建Hadoop集群(Centos7.0)
Hadoop集群安装 概述 集群 cluster,将很多任务进程分布到多台计算机上:通过联合使用多台计算机的存储.计算能力完成更庞大的任务.为了实现无限量的存储和计算能力,在生产环境中必须使用集群来满 ...
- hdfs启用垃圾站功能
在core-site.xml文件中添加如下内容: ##开启回收站功能,设置保存7天删除数据信息 <property> <name>f ...
- 冒泡排序之python
冒泡排序(Bubble sort) 两两比较相邻记录的关键字,如果反序则交换,直到没有反序记录为止. 1.算法描述: 比较相邻的元素.如果第一个比第二个大,就交换它们两个: 对每一对相邻元素作同样的工 ...
- ubuntu 12.10上安装tftpd-hpa
ubuntu 12.10上安装tftpd-hpa 1)安装tftp-hpa,tftpd-hpa sudo apt-get install tftp-hpa tftpd-hpa tftp-hpa是cli ...
- 在浏览器地址栏输入一个URL后回车,将会发生的事情?
https://yq.aliyun.com/articles/20667
- 应该掌握的JQuery的7个效果
一: 语法: $(selector).hide(speed,callback); $(selector).show(speed,callback); 实例 //点击隐藏 $("#hide&q ...
- netcat/curl/wget/smb/icmp ping -p/dns/telnet
通过SMB协议,在目标服务器和主机之间建立网络共享连接,然后将目标服务器上的文件做分享,接着就可以在主机端将分享的文件copy下来啦.操作的命令如下, net use h: \\xxx.xxx.xxx ...
- iOS-CoreLocation地理编码(转载)
一.简单说明 CLGeocoder:地理编码器,其中Geo是地理的英文单词Geography的简写. 1.使用CLGeocoder可以完成“地理编码”和“反地理编码” 地理编码:根据给定的地名,获得具 ...
- Wireless Network--poj2236(并查集)
Description An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have ...
- 【python-opencv】20-图像金字塔
知识点介绍 图像金字塔原理: 高斯金字塔 拉普拉斯金字塔: 代码层面知识点: cv2.PyrDown:降采样 cv2.PyrUp:升采样 高斯金字塔与拉普拉斯金字塔 图像金字塔是图像中多尺度表达的 ...