Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
如此辛苦 水过~~~const f:array[1..16]of longint=(%10011,%100111,%1001110,%10001100, %100110001,%1001110010,%10011100100,%100011001000, %1001100010000,%10011100100000,%100111001000000,%1000110010000000, %11000100000000,%111001000000000,%1110010000000000,%1100100000000000); var a:array[0..4,0..4]of longint; q,d:array[0..65536]of longint; u:array[0..65536]of boolean; i,j,k,m,n,start:longint; procedure init; var i,j:longint;s:string; begin start:=0; for i:=1 to 4 do begin readln(s); for j:=1 to 4 do begin if s[j]='w' then a[i,j]:=0; if s[j]='b' then a[i,j]:=1; end; end; for i:=1 to 4 do for j:=1 to 4 do inc(start,a[i,j] shl (16-((i-1)*4+j))); //writeln(start); end; procedure bfs; var i,j,head,tail,now,nd:longint; begin fillchar(u,sizeof(u),true); u[start]:=false;q[1]:=start;d[1]:=0; head:=1;tail:=2; if (start=0)or(start=65536) then begin writeln('0');halt;end; while head<>tail do begin now:=q[head]; if (now=0)or (now=65535) then begin writeln(d[head]);halt;end; for i:=1 to 16 do begin nd:=now xor f[i]; if u[nd] then begin u[nd]:=false; q[tail]:=nd; d[tail]:=d[head]+1; if (nd=0)or(nd=65535) then begin writeln(d[tail]);halt;end; inc(tail); end; end; inc(head); end; writeln('Impossible'); end; begin init; bfs; end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator