bzoj 1689: [Usaco2005 Open] Muddy roads 泥泞的路(模拟)
2017-09-12 19:15
507 查看
1689: [Usaco2005 Open] Muddy roads 泥泞的路
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 445 Solved: 307
[Submit][Status][Discuss]
Description
Farmer John has a problem: the dirt road from his farm to town has suffered in the recent rainstorms and now contains (1 <= N <= 10,000) mud pools. Farmer John has a collectionof wooden planks of length L that he can use to bridge these mud pools. He can overlap planks and the ends do not need to be anchored on the ground. However, he must cover each pool completely. Given the mud pools, help FJ figure out the minimum number of
planks he needs in order to completely cover all the mud pools.
牧场里下了一场暴雨,泥泞道路上出现了许多水坑,约翰想用一批长度为L的木板将这些水坑盖住. 牧场里的道路可以看成一根数轴,每个水坑可以用数轴上的两个坐标表示,如(3,6)表示从3到6有一个长度为3的水坑.所有的水坑都是不重叠的,(3,6)和(6,9)可以出现在同一个输入数据中,因为它们是两个连续的水坑,但不重叠.
请你帮助约翰计算最少要用多少块木板才能将所有水坑盖住
Input
* Line 1: Two space-separated integers: N and L * Lines 2..N+1: Line i+1 contains two space-separated integers: s_i and e_i (0 <= s_i < e_i <= 1,000,000,000) that specify the start and end points ofa mud pool along the road. The mud pools will not overlap. These numbers specify points, so a mud pool from 35 to 39 can be covered by a single board of length 4. Mud pools at (3,6) and (6,9) are not considered to overlap.
第1行有二个用空格隔开的整数N和L.其中1≤N≤10000,表示水坑总数.L为木板长度.
接下来的N行每行有二个用整数si和ei(0≤si<ei≤109),表示一个水坑的两个坐标.
Output
* Line 1: The miminum number of planks FJ needs to use.一个整数,表示约翰盖住所有水坑最少要用多少块长为L的木板.
Sample Input
3 31 6
13 17
8 12
Sample Output
5把所有的线段排个序模拟下就好了,DP都不用
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef struct Line
{
int x, y;
bool operator < (const Line &b) const
{
if(x<b.x)
return 1;
return 0;
}
}Line;
Line s[10005];
int main(void)
{
int n, m, i, now, ans, temp;
scanf("%d%d", &n, &m);
for(i=1;i<=n;i++)
{
scanf("%d%d", &s[i].x, &s[i].y);
s[i].y--;
}
sort(s+1, s+n+1);
now = ans = 0;
for(i=1;i<=n;i++)
{
if(now>s[i].y)
continue;
temp = (s[i].y-max(now, s[i].x)+1)/m;
now = max(now, s[i].x)+temp*m;
if(now<=s[i].y)
now += m, temp++;
ans += temp;
}
printf("%d\n", ans);
return 0;
}
相关文章推荐
- BZOJ 1689 [Usaco2005 Open] Muddy roads 泥泞的路 模拟
- bzoj1689 [Usaco2005 Open] Muddy roads 泥泞的路
- bzoj1689 [Usaco2005 Open] Muddy roads 泥泞的路
- bzoj 1689: [Usaco2005 Open] Muddy roads 泥泞的路【贪心】
- bzoj 1689: [Usaco2005 Open] Muddy roads 泥泞的路
- bzoj1689: [Usaco2005 Open] Muddy roads 泥泞的路
- 【BZOJ】1689: [Usaco2005 Open] Muddy roads 泥泞的路(贪心)
- bzoj1689 [Usaco2005 Open] Muddy roads 泥泞的路
- 1689: [Usaco2005 Open] Muddy roads 泥泞的路
- BZOJ 1689: [Usaco2005 Open] Muddy roads 泥泞的路
- 【bzoj1689】[Usaco2005 Mar]Checking an Alibi 不在场的证明
- 【BZOJ】3403: [Usaco2009 Open]Cow Line 直线上的牛(模拟)
- BZOJ1689: [Usaco2005 Open] Muddy roads
- Bzoj 1687: [Usaco2005 Open]Navigating the City 城市交通 广搜,深搜
- 【bzoj1688】[USACO2005 Open]Disease Manangement 疾病管理 状态压缩dp+背包dp
- bzoj 1747: [Usaco2005 open]Expedition 探险 贪心
- [BZOJ] 1688: [Usaco2005 Open]Disease Manangement 疾病管理
- BZOJ_1621_[Usaco2008_Open]_Roads_Around_The_Farm_分岔路口(模拟+大水题)
- BZOJ[1735][Usaco2005 jan]Muddy Fields 泥泞的牧场 网络流
- bzoj1748 [Usaco2005 open]Around the world 环球飞行