社区讨论

一个问题

P4027[NOI2007] 货币兑换参与者 3已保存回复 3

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
3 条
当前快照
1 份
快照标识符
@mi6o4g99
此快照首次捕获于
2025/11/20 08:03
4 个月前
此快照最后确认于
2025/11/20 08:03
4 个月前
查看原帖
这是我的CDQ分治代码:
CPP
void CDQ(int l, int r)
{
	//The bottom
	if (l == r) {
		chkmax(f[l], f[l - 1]);
		A[l].x = getdp(f[l], l), A[l].y = A[l].x / A[l].rt;
		return ;
	}

	//Divide them into 2 parts
	int mid = (l + r) >> 1, x = l, y = mid + 1, cur = 1;
	For(i, l, r)
		if (A[i].id <= mid) t[x ++] = A[i]; else t[y ++] = A[i];
	For(i, l, r) A[i] = t[i];

	//Deal with the left part
	CDQ(l, mid);

	//Get the convex line of the left points
	top = 0;
	For(i, l, mid) {
		//We can build the convex line directly because we have sort them before(At the last of this function)
		while (top > 1 && Slope(stk[top - 1], stk[top]) < Slope(stk[top - 1], i) + eps) -- top;//NOTICE: The '+ eps' is necessary or you will get only 80 points
		stk[++ top] = i;
	}
	stk[++ top] = 0;//To deal with the dicision on the last element

	//Update the right part with the convex line
	For(i, mid + 1, r) {
		while (cur < top && Slope(stk[cur], stk[cur + 1]) > A[i].sl) ++ cur;
		chkmax(f[A[i].id], A[stk[cur]].x * A[i].a + A[stk[cur]].y * A[i].b);
	}

	//Deal with the right part
	CDQ(mid + 1, r);

	//Sort according to x
	x = l, y = mid + 1;
	For(i, l, r)
		if (x == mid + 1) t[i] = A[y ++];
		else if (y == r + 1) t[i] = A[x ++];
		else if (A[x].x < A[y].x || (A[x].x - A[y].x < eps && A[x].y < A[y].y)) t[i] = A[x ++];
		else t[i] = A[y ++];
	For(i, l, r) A[i] = t[i];
}
哪位dalao知道为什么其中注释的NOTICE处不+eps就会WA成80啊。。

回复

3 条回复,欢迎继续交流。

正在加载回复...