📄 ac1104.pas
字号:
program tju1104;
const
maxr=100;
var
x1,x2,y1,y2:array[1..maxr]of word;
l:array[1..maxr*2]of word;
b:array[1..maxr*2]of boolean;
r,i,t:word;
sum:longint;
procedure qsort(s,t:word);
var
p,i,j,tl:word;
tb:boolean;
begin
if s>=t then exit;
p:=s+random(t-s+1);
tl:=l[p];tb:=b[p];l[p]:=l[s];b[p]:=b[s];
i:=s;j:=t;
repeat
while (i<j) and (l[j]>=tl) do dec(j);
if i=j then break;l[i]:=l[j];b[i]:=b[j];inc(i);
while (i<j) and (l[i]<=tl) do inc(i);
if i=j then break;l[j]:=l[i];b[j]:=b[i];dec(j);
until i=j;
l[i]:=tl;b[i]:=tb;
qsort(s,i-1);
qsort(i+1,t);
end;
procedure cal_one(u,v,h,x:word);
var
c,i,s:word;
begin
c:=0;
for i:=1 to r do
if ((y1[i]<h) or (y1[i]=h) and (i<x)) and (y2[i]>=h) and (x1[i]<v) and (x2[i]>u) and (i<>x) then begin
inc(c);if x1[i]<u then l[c]:=u else l[c]:=x1[i];b[c]:=true;
inc(c);if x2[i]>v then l[c]:=v else l[c]:=x2[i];b[c]:=false;
end;
qsort(1,c);
h:=0;s:=0;
for i:=1 to c do
if b[i] then begin
if h=0 then x:=l[i];inc(h);
end
else begin
dec(h);if h=0 then inc(s,l[i]-x);
end;
inc(sum,v-u-s);
end;
procedure cal_all;
begin
for i:=1 to r do
cal_one(x1[i],x2[i],y1[i],i);
end;
begin
repeat
read(r);
for i:=1 to r do
read(x1[i],x2[i],y1[i],y2[i]);
sum:=0;
cal_all;
for i:=1 to r do begin
t:=x1[i];x1[i]:=y1[i];y1[i]:=t;
t:=x2[i];x2[i]:=y2[i];y2[i]:=t;
end;
cal_all;
writeln(sum*2);
until seekeof;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -