bzoj 1689: [Usaco2005 Open] Muddy roads 泥泞的路【贪心】
按左端点排序,贪心的选即可
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=10005;
int n,l,p,ans;
struct qwe
{
int x,y;
}a[N];
bool cmp(const qwe &a,const qwe &b)
{
return a.x<b.x;
}
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
int main()
{
n=read(),l=read();
for(int i=1;i<=n;i++)
a[i].x=read(),a[i].y=read();
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++)
if(p<a[i].y)
{
p=max(p,a[i].x);
while(p<a[i].y)
ans++,p+=l;
}
printf("%d",ans);
return 0;
}
bzoj 1689: [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 ...
- 【BZOJ】1689: [Usaco2005 Open] Muddy roads 泥泞的路(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1689 一开始我也想到了贪心,,,策略是如果两个连续的水池的距离小于l的话,那么就将他们链接起来,,, ...
- bzoj1689 / P1589 [Usaco2005 Open] Muddy roads 泥泞的路
P1589 [Usaco2005 Open] Muddy roads 泥泞的路 简单的模拟题. 给水坑排个序,蓝后贪心放板子. 注意边界细节. #include<iostream> #in ...
- bzoj1689 [Usaco2005 Open] Muddy roads 泥泞的路
Description Farmer John has a problem: the dirt road from his farm to town has suffered in the recen ...
- P1689: [Usaco2005 Open] Muddy roads 泥泞的路
水题,模拟就行了,别忘了L>=r的时候直接更新下一个的L然后continue type node=record l,r:longint; end; var n,l,i,ans:longint; ...
- 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.大雨将没有长草的土地弄得泥泞不堪,可是小心的奶牛们不想在吃草的时候弄脏她们的蹄子. 为了防止她们的蹄 ...
- BZOJ1689: [Usaco2005 Open] Muddy roads
1689: [Usaco2005 Open] Muddy roads Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 147 Solved: 107[Su ...
- [Usaco2005 Jan]Muddy Fields泥泞的牧场
Description 雨连续不断的击打了放牛的牧场,一个R行C列的格子(1<=R<=50,1<=C<=50).虽然这对草来说是件好事,但这却使得一些没有草遮盖的土地变得很泥泞 ...
随机推荐
- [K3Cloud] QueryService使用注意事项
QueryServlice是目前查询数据非常好用的服务,但目前在使用过程中由于使用不当产生不少问题,下面将一一解答: 1.在查询一些实体关键字段如实体主键.分录序号时,条件中的别名怎么会变来变去? ...
- Nginx 的 server_names_hash_bucket_size 问题
在 Nginx 0.6.35 的版本中,配置多个 server 虚拟主机,必须要在配置文档中 http { 里头加上 server_names_hash_bucket_size 64; 这么一句 ht ...
- nyoj_758_分苹果
分苹果 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法? (注意:假如有3个盘子7 ...
- I - Balancing Act POJ - 1655
Consider a tree T with N (1 <= N <= 20,000) nodes numbered 1...N. Deleting any node from the t ...
- POJ1328 Radar Installation 解题报告
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- cache and database
This article referenced from http://coolshell.cn/articles/17416.html We all know that high concurren ...
- python 时间四舍五入
假设时间格式为 YYYYMMDDhhmm , 比如201508010001 代表2015年8月1日0点01分. 现在有需求,要求一个start 和一个 end 变量的字符串 都是这种格式的时间. 需要 ...
- Mybatis中的ognl表达式。及myabtis where标签/if test标签/trim标签
1.mybatis默认支持使用ognl表达式来生成动态sql语句 MyBatis中可以使用OGNL的地方有两处: 动态SQL表达式中 ${param}参数中 上面这两处地方在MyBatis中处理的时候 ...
- 关于错误 e297: write error in swap file;E297: 交换文件写入错误
在linux系统下修改文件vim的时候,忽然报错 E297: 交换文件写入错误 或者 e297: write error in swap file 原因:硬盘空间不足,我去,就剩下16M了
- 华为OJ2011-最长公共子串
一.题目描述 描述: 计算两个字符串的最大公共子串(Longest Common Substring)的长度,字符区分大小写. 输入: 输入两个字符串 输出: 输出一个整数 样例输入: asdfas ...