灵异事件……求解(在线等)
  • 板块P1589 泥泞路
  • 楼主emiermao
  • 当前回复10
  • 已保存回复10
  • 发布时间2020/10/7 18:57
  • 上次更新2023/11/5 11:40:20
查看原帖
灵异事件……求解(在线等)
218051
emiermao楼主2020/10/7 18:57

这是一份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解释,蟹蟹

2020/10/7 18:57
加载中...