|
|
вернуться в форумWhere my program fail? I use simple simulation of "hand moves". I cannot create a test, where my program fail, but I have received WA :-( Could anyone tell me, where is my bug? VAR A:Array[1..500,1..50] of integer; M,N:integer; PROCEDURE ReadData; var P,i,j:integer; begin readln(M,N); for i:=1 to M do begin for j:=1 to N do read(A[i][j]); readln; end; end; FUNCTION MakeChanges(K,P:integer):longint; var Sum:longint; C,i:integer; bool:boolean; begin Sum:=0; repeat inc(Sum); C:=A[K][P]; A[K][P]:=K; bool:=true; for i:=1 to N do if A[C][i]<>C then begin bool:=false; K:=C; P:=i; break end; until bool; MakeChanges:=Sum; end; PROCEDURE Process; var i,j:integer; Sum:longint; begin Sum:=0; for i:=1 to M do for j:=1 to N do if A[i][j]<>i then Sum:=Sum+MakeChanges(i,j); writeln(Sum); end; BEGIN ReadData; Process; END. You have problems if the graph is not connected - a test for you (+) For example, for this test: 4 1 2 1 4 3 The answer is 5, not 4. Thanks! Thanks, I ge AC, but I write new version of solution. Simulations doesn't work! |
|
|