警示后人
查看原帖
警示后人
469487
wxw_zl楼主2023/10/3 16:26

开始re Subtask1

发现是在使用双指针的时候忘记控制边界,造成死循环

原来:

bool check(int t) { //检查最小跳跃距离
	int cnt = 0; //统计要移走的石头数目
	for (int i = 0, j; i <= n;) {
		j = i + 1;
		while (a[j] - a[i] < t) {
			cnt++;
			j++;
		}
		i = j;
	}
	if (cnt <= m)return 1;
	return 0;
}

改正后:

bool check(int t) { //检查最小跳跃距离
	int cnt = 0; //统计要移走的石头数目
	for (int i = 0, j; i <= n;) {
		j = i + 1;
		while (a[j] - a[i] < t && j <= n + 1) {
			cnt++;
			j++;
		}
		i = j;
	}
	if (cnt <= m)return 1;
	return 0;
}
2023/10/3 16:26
加载中...