标签:
Description
Input
Output
Sample Input
3 3 1 6 13 17 8 12
Sample Output
5
Hint
111222..333444555....
.MMMMM..MMMM.MMMM....
012345678901234567890
Source
1 #include<iostream> 2 #include<algorithm> 3 #include<cstring> 4 #include<cstdio> 5 #include<cmath> 6 using namespace std; 7 const int mxn=12000; 8 struct wd{ 9 int x,y; 10 bool operator < (const wd rhd){ 11 return x<rhd.x; 12 } 13 }a[mxn]; 14 int n,L; 15 int main(){ 16 scanf("%d%d",&n,&L); 17 int i,j; 18 for(i=1;i<=n;i++){ 19 scanf("%d%d",&a[i].x,&a[i].y); 20 } 21 sort(a+1,a+n+1); 22 int cnt=0; 23 int now=0; 24 for(i=1;i<=n;i++){ 25 now=max(now,a[i].x);//开始铺 26 while(now<a[i].y){ 27 now+=L; 28 cnt++; 29 } 30 } 31 printf("%d\n",cnt); 32 return 0; 33 }
标签:
原文地址:http://www.cnblogs.com/SilverNebula/p/5641944.html