题意:
• 在平面上画了N个长方形,每个长方形的边平行于坐标轴并且顶点坐标为整数。我们用以下方式定义印版:
– 每个长方形是一个印版;
– 如果两个印版有公共的边或内部,那么它们组成新的印版,否则这些印版是分离的
就是把两个相交的矩形变成一个
思路:
判断他们是否是相交,是的话就用并查集放到一个集合里面去,然后看被分成几个集合就好了
const
maxn=10000;
var
f,x1,y1,x2,y2,t:array [1..maxn] of longint;
i,j,n,ans:longint;
function father(x:longint):longint;
var
i,j:longint;
begin
if x<>f[x] then father:=father(f[x])
else father:=x;
f[x]:=father;
end;
function cheak(i,j:longint):boolean;
begin
if (x1[i]>x2[j]) or (x2[i]<x1[j]) then exit(false);
if (y1[i]>y2[j]) or (y2[i]<y1[j]) then exit(false);
if (x2[i]=x1[j]) and (y1[i]=y2[j]) then exit(false);
if (x1[i]=x2[j]) and (y2[i]=y1[j]) then exit(false);
if (x2[i]=x1[j]) and (y2[i]=y1[j]) then exit(false);
if (x1[i]=x2[j]) and (y1[i]=y2[j]) then exit(false);
exit(true);
end;
begin
readln(n);
for i:=1 to n do
readln(x1[i],y1[i],x2[i],y2[i]);
for i:=1 to n do
f[i]:=i;
for i:=1 to n do
for j:=i+1 to n do
if cheak(i,j) then
f[father(i)]:=father(j);
for i:=1 to n do
if father(f[i])<>0 then inc(t[father(f[i])]);
for i:=1 to 10000 do
if t[i]<>0 then inc(ans);
writeln(ans);
end.