BZOJ 1010 玩具装箱

BZOJ 1010 玩具装箱

我发现斜率优化的大多都是模板题。

//By YY_More
#include
struct point{
	long long x,y;
} now,D[50010];
int L,R,N,W;
long long C[500010];
inline long long xmul(point a,point b,point c){
	return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
}	
int main(){
	scanf("%d%d",&N,&W);
	for (int i=1;i<=N;i++){
		scanf("%lld",&C[i]);
		C[i]+=C[i-1];
	}
	for (int i=1;i<=N;i++){
		while (L=D[L+1].y-2*(i+C[i]-W-1)*D[L+1].x) L++;
		now.x=i+C[i];now.y=D[L].y-2*(i+C[i]-W-1)*D[L].x+(i+C[i]-W-1)*(i+C[i]-W-1)+(i+C[i])*(i+C[i]);
		while (L
posted on 2011-07-31 09:04  YY_More 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/yymore/archive/2011/07/31/2122494.html

你可能感兴趣的:(BZOJ 1010 玩具装箱)