捞) 求救!(贪心)
  • 板块P1589 泥泞路
  • 楼主轻绘
  • 当前回复0
  • 已保存回复0
  • 发布时间2020/10/12 22:49
  • 上次更新2023/11/5 10:53:19
查看原帖
捞) 求救!(贪心)
202606
轻绘楼主2020/10/12 22:49
#include<bits/stdc++.h>
using namespace std;
int n,ll,now,ans,len,l,r;
struct note{
    int x,y;
}a[20000];
bool cmp(note x,note y){
    if(x.x==x.y)
        return x.y<y.y;
    return x.x<y.x; 
}
int main(){
    scanf("%d%d",&n,&ll);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&a[i].x,&a[i].y);
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++){
        int o=0;
        now=max(now,a[i].x);
        if((a[i].y-now)%ll!=0){
            o++;
        }
        o+=(a[i].y-now)/ll;
        if(o<=0){
            continue;
        }
        //printf("%d\n",o);
        now+=o*ll;
        ans+=o;
    }
    printf("%d",ans);
    return 0;
}

WA六个点 看不出哪里有问题

2020/10/12 22:49
加载中...