|
|
back to boardPlease, help me !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! I don't understand why my program get WA. Please, help me!!!!!!!!!!!!!!!!! Const f1=0; f2=2 shl 15-1; dp:Array[1..4]Of Integer=(-4,-1,1,4); Var v,ykw,ykr:Integer; Og:Array[1..f2]Of Integer; Mv:Array[0..f2]Of Integer; b:Boolean; Procedure Init; Begin End; Procedure ReadData; Var t,i,j:Integer; ch:Char; Begin v:=0;t:=0; For i:=1 To 4 Do Begin For j:=1 To 4 Do Begin Inc(t); Read(ch); If ch='w' Then If t=1 Then v:=1 Else v:=v Xor (2 shl (t-2)); End; ReadLn; End; End; Function GetNew(p:Integer):Integer; Var i,j,new,np:Integer; Begin If p=1 then new:=v Xor 1 Else new:=v Xor (2 shl(p-2)); For i:=1 To 4 Do Begin np:=p+dp[i]; If (np<1) Or (np>16) Then Continue; If np=1 Then new:=new Xor 1 Else new:=new Xor (2 shl (np-2)); End; GetNew:=new; End; Procedure Solve; Var i,j:Integer; Begin FillChar(Og,SizeOf(Og),0);ykw:=0;ykr:=0; FillChar(Mv,SizeOf(Mv),0);Mv[v]:=1; Inc(ykw);Og[ykw]:=v; b:=True; If (v=f1) Or (v=f2) Then Exit; While ykr<ykw Do Begin Inc(ykr);v:=Og[ykr]; For i:=1 To 16 Do Begin j:=GetNew(i); If Mv[j]=0 Then Begin Inc(ykw);Og[ykw]:=j; Mv[j]:=Mv[v]+1; If (j=f1) Or (j=f2) Then Exit; End; End; End; b:=False; End; Procedure OutData; Begin If Not b Then Write('Impossible') Else Write(Mv[Og[ykw]]-1); End; Begin Init; ReadData; Solve; OutData; End. |
|
|