BZOJ1689: [Usaco2005 Open] Muddy roads
1689: [Usaco2005 Open] Muddy roads
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 147 Solved: 107
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
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
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
#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的更多相关文章
- bzoj1689 [Usaco2005 Open] Muddy roads 泥泞的路
Description Farmer John has a problem: the dirt road from his farm to town has suffered in the recen ...
- bzoj1689 / P1589 [Usaco2005 Open] Muddy roads 泥泞的路
P1589 [Usaco2005 Open] Muddy roads 泥泞的路 简单的模拟题. 给水坑排个序,蓝后贪心放板子. 注意边界细节. #include<iostream> #in ...
- bzoj 1689: [Usaco2005 Open] Muddy roads 泥泞的路
1689: [Usaco2005 Open] Muddy roads 泥泞的路 Description Farmer John has a problem: the dirt road from hi ...
- 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 泥泞的路(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1689 一开始我也想到了贪心,,,策略是如果两个连续的水池的距离小于l的话,那么就将他们链接起来,,, ...
- bzoj 1689: [Usaco2005 Open] Muddy roads 泥泞的路【贪心】
按左端点排序,贪心的选即可 #include<iostream> #include<cstdio> #include<algorithm> using namesp ...
- bzoj 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 最小点覆盖
链接 1735: [Usaco2005 jan]Muddy Fields 泥泞的牧场 思路 这就是个上一篇的稍微麻烦版(是变脸版,其实没麻烦) 用边长为1的模板覆盖地图上的没有长草的土地,不能覆盖草地 ...
- [USACO2005][POJ2226]Muddy Fields(二分图最小点覆盖)
题目:http://poj.org/problem?id=2226 题意:给你一个字符矩阵,每个位置只能有"*"或者“.",连续的横着或者竖的“*"可以用一块木 ...
- POJ2437 Muddy roads
Description Farmer John has a problem: the dirt road from his farm to town has suffered in the recen ...
随机推荐
- chomp方法
chomp方法属于String类里面的: "hello".chomp #=> "hello" "hello\n".chomp #=&g ...
- ORACLE归档模式和非归档模式的利与弊
转: 在Oracle数据库中,主要有两种日志操作模式,分别为非归档模式与归档模式.默认情况下,数据库采用的是非归档模式.作为一个合格的数据库管理员,应当深入了解这两种日志操作模式的特点,并且在数据库建 ...
- iOS UITableView 修改滚动条颜色 默认选中第一条
//隐藏 self.tableView.showsVerticalScrollIndicator = NO; //修改颜色 self.tableView.indicatorStyle=UIScroll ...
- (转)Maven实战(二)构建简单Maven项目
上一节讲了maven的安装和配置,这一节我们来学习一下创建一个简单的Maven项目 1. 用Maven 命令创建一个简单的Maven项目 在cmd中运行如下命令: mvn archetype:gene ...
- MAC安装SVNServer
MAC已经自带了SVN,所以,直接使用就好 1.创建svn repository svnadmin create /path/svn/pro //仓库位置,svn是svn的目录,pro是一个版本库的 ...
- Oracle之事务
一,oracle的事务: 是指对数据操作的一系列动作的统称.即:事务的任务便是使数据库从一种状态变换成为另一种状态,这不同于文件系统,它是数据库所特用的. 事务有四大特性(ACID): 1,原子性(a ...
- DateBox( 日期输入框) 组件
本节课重点了解 EasyUI 中 DateBox(日期输入框)组件的使用方法,这个组件依赖于 Combo(自定义下拉框)和 Calendar(日历). 一. 加载方式//class 加载方式<i ...
- SqlServer跨域查询
SELECT * FROM OPENDATASOURCE('SQLOLEDB','Data Source=192.168.1.14;User ID=sa;Password=sql.com').eBui ...
- js获取当前的时间(包含星期)
<script type="text/javascript"> setInterval("www_zzje_net.innerHTML=new ...
- jQuery事件与事件对象
事件是脚本编程的灵魂,本篇来介绍jQuery中的事件处理及事件对象. 事件与事件对象 首先,我们来看一下经常使用的添加事件的方式: <input type="button" ...