这是一份AC代码
#include <bits/stdc++.h>
using namespace std;
struct Node {
int s, e;
};
Node earth[10005];
bool cmp (Node a, Node b) {
return a.s < b.s;
}
int main () {
int n, l;
scanf("%d %d", &n, &l);
int ans = 0;
for (int i = 1; i <= n; i++) {
scanf("%d %d", &earth[i].s, &earth[i].e);
}
sort(earth + 1, earth + n + 1, cmp);
for (int i = 1; i <= n; i++) {
int el = earth[i].e - earth[i].s;
if (el % l == 0) {
ans += (el / l);
continue;
}else {
ans += (el + l) / l;
}
earth[i+1].s = max(earth[i + 1].s, earth[i].s + (int)ceil((double)el / l) *l);
}
printf("%d\n", ans);
return 0;
}
其中一行
ans += (el + l) / l;
改成
ans += el / l + 1;
此时再提交,就成了这样子,40分unaccepted
求各位dalao解释,蟹蟹