//poj 2437
//sep9
#include <iostream>
#include <algorithm>
using namespace std;
int N,L;
struct SEG
{
int a,b;
}seg[10024];
int cmp(SEG x,SEG y)
{
return x.a<y.a;
}
int main()
{
scanf("%d%d",&N,&L);
for(int i=0;i<N;++i)
scanf("%d%d",&seg[i].a,&seg[i].b);
sort(seg,seg+N,cmp);
int ans=0,pos=0;
for(int i=0;i<N;++i){
int tmp=seg[i].b-seg[i].a;
if(pos>=seg[i].b)
continue;
if(pos<=seg[i].a){
ans+=tmp%L==0?tmp/L:tmp/L+1;
pos=tmp%L==0?seg[i].b:seg[i].a+L*(tmp/L+1);
continue;
}
tmp=seg[i].b-pos;
ans+=tmp%L==0?tmp/L:tmp/L+1;
pos=tmp%L==0?seg[i].b:pos+L*(tmp/L+1);
}
printf("%d",ans);
return 0;
}
poj 2437 Muddy roads 贪心
最新推荐文章于 2016-08-21 19:26:18 发布