N个不同的颜色的不透明的长方形(1 <= N <= 1000)被放置在一张横宽为A竖长为B的白纸上。这些长方形被放置时,保证了它们的边与白纸的边缘平行。所有的长方形都放置在白纸内,所以我们会看到不同形状的各种颜色。坐标系统的原点(0,0)设在这张白纸的左下角,而坐标轴则平行于边缘。
浮水法
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
var x1,x2,y1,y2,c:array[0..1000]of longint;
ans:array[1..3000]of longint;
i,j,k,n,max:longint;
procedure make(l,r,u,d,k,c:longint);
begin
while (k<=n)and((r<=x1[k])or(l>=x2[k])or(u>=y2[k])or(d<=y1[k])) do inc(k);
if k>n thenbegin ans[c]:=ans[c]+(r-l)*(d-u);exit;end;
if l<=x1[k] thenbegin make(l,x1[k],u,d,k+1,c);l:=x1[k];end;
if r>=x2[k] thenbegin make(x2[k],r,u,d,k+1,c);r:=x2[k];end;
if (u<=y1[k]) thenbegin make(l,r,u,y1[k],k+1,c);u:=y1[k];end;
if (d>=y2[k]) thenbegin make(l,r,y2[k],d,k+1,c);d:=y2[k];end;
end;
begin
assign(input,'rect1.in');reset(input);
assign(output,'rect1.out');rewrite(output);
readln(x2[0],y2[0],n);
c[0]:=1;
for i:=1to n do
begin
readln(x1[i],y1[i],x2[i],y2[i],c[i]);
if c[i]>max then max:=c[i];
end;
for i:=n downto0do
begin
make(x1[i],x2[i],y1[i],y2[i],i+1,c[i]);
end;
for i:=1to max do
if ans[i]<>0then writeln(i,'',ans[i]);
close(input);close(output);
end.
ans:array[1..3000]of longint;
i,j,k,n,max:longint;
procedure make(l,r,u,d,k,c:longint);
begin
while (k<=n)and((r<=x1[k])or(l>=x2[k])or(u>=y2[k])or(d<=y1[k])) do inc(k);
if k>n thenbegin ans[c]:=ans[c]+(r-l)*(d-u);exit;end;
if l<=x1[k] thenbegin make(l,x1[k],u,d,k+1,c);l:=x1[k];end;
if r>=x2[k] thenbegin make(x2[k],r,u,d,k+1,c);r:=x2[k];end;
if (u<=y1[k]) thenbegin make(l,r,u,y1[k],k+1,c);u:=y1[k];end;
if (d>=y2[k]) thenbegin make(l,r,y2[k],d,k+1,c);d:=y2[k];end;
end;
begin
assign(input,'rect1.in');reset(input);
assign(output,'rect1.out');rewrite(output);
readln(x2[0],y2[0],n);
c[0]:=1;
for i:=1to n do
begin
readln(x1[i],y1[i],x2[i],y2[i],c[i]);
if c[i]>max then max:=c[i];
end;
for i:=n downto0do
begin
make(x1[i],x2[i],y1[i],y2[i],i+1,c[i]);
end;
for i:=1to max do
if ans[i]<>0then writeln(i,'',ans[i]);
close(input);close(output);
end.