题意:一个3*3的矩形可以用若干个2*2的矩形去覆盖,现在给出一个最终的图,求它是否合法.
分析:就是拓扑排序.
code:
const yes='THESE WINDOWS ARE CLEAN'; no='THESE WINDOWS ARE BROKEN'; var sta:array[1..9,0..1] of longint=((1,1),(1,2),(1,3), (2,1),(2,2),(2,3), (3,1),(3,2),(3,3)); map:array[0..10,0..10] of longint; link:array[0..10,0..10] of boolean; incount:array[0..10] of longint; vis:array[0..10] of boolean; o,i,j,t,now:longint; st,en:string; flag,found:boolean; function check:boolean; var oo:longint; begin for oo:=1 to 9 do if incount[oo]<>0 then exit(false); exit(true); end; begin readln(st); while st<>'ENDOFINPUT' do begin fillchar(map,sizeof(map),0); fillchar(vis,sizeof(vis),0); fillchar(link,sizeof(link),0); fillchar(incount,sizeof(incount),0); for i:=1 to 4 do begin for j:=1 to 4 do read(map[i,j]); readln; end; readln(en); for o:=1 to 9 do for i:=sta[o,0] to sta[o,0]+1 do for j:=sta[o,1] to sta[o,1]+1 do if (map[i,j]<>o)and(not link[map[i,j],o]) then begin inc(incount[o]); link[map[i,j],o]:=true; end; flag:=true; for t:=1 to 9 do begin found:=false; for i:=1 to 9 do if (incount[i]=0)and(not vis[i]) then begin now:=i; found:=true; vis[i]:=true; break; end; if (found=false)and(not check) then begin flag:=false; break; end; for i:=1 to 9 do if link[now,i] then begin dec(incount[i]); link[now,i]:=false; end; end; if not flag then writeln(no) else writeln(yes); readln(st); end; end.