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).虽然这对草来说是件好事,但这却使得一些没有草遮盖的土地变得很泥泞 ...
随机推荐
- TensorFlow 度量张量和张量或者和零之间的误差值
用于一个回归任务或者正则问题 # l2损失,output= sum(x ** 2)/2 inputdata = tf.Variable(np.random.rand(2,3), dtype=np.fl ...
- 在浏览器地址栏输入一个URL后回车,将会发生的事情?
https://yq.aliyun.com/articles/20667
- JS "trycatch工厂模式"
大家都用过Ajax的异步交互,下面的代码中使用 "trycatch工厂模式" 来进行针对Ajax请求对象的变化点进行封装 <script type="text/ ...
- cas sso原理
以下转载至https://blog.csdn.net/javaloveiphone/article/details/52439613 从结构上看,CAS包含两个部分:CAS Server 和CAS C ...
- Parity game---poj1733
Description Now and then you play the following game with your friend. Your friend writes down a seq ...
- Selenium定位元素-Xpath的使用方法
工具 Xpath的练习建议下载火狐浏览器,下载插件Firebug.Firepath. 由于最新版火狐不支持Firebug等扩展工具了,所以需要下载49版以下的版本安装https://ftp.mozil ...
- 查看crontab的日志记录定位定时任务问题
1.linux 看 /var/log/cron这个文件就可以,可以用tail -f /var/log/cron观察 2.unix 在 /var/spool/cron/tmp文件中,有croutXXX0 ...
- linux命令:locate
1.命令简介 locate(locate) 命令用来查找文件或目录. locate命令要比find -name快得多,原因在于它不搜索具体目录,而是搜索一个数据库/var/lib/ml ...
- 为什么要用Markov chain Monte Carlo (MCMC)
马尔科夫链的蒙特卡洛采样的核心思想是构造一个Markov chain,使得从任意一个状态采样开始,按该Markov chain转移,经过一段时间的采样,逼近平稳分布stationary distrib ...
- 获取多达 16GB 的 Dropbox 免费空间!
Dropbox官网