ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1789. Searching for the Dodecahedron

why this algo is wrong
Posted by nomercy 14 Feb 2016 15:52
ans.push_back(2);
    ans.push_back(2);
    for (int i = 2;;++i){
        if (i == n){
            ans.push_back(i);
            break;
        }
        ans.push_back(i+1);
        ans.push_back(i-1);
        ans.push_back(i);
    }

WA3

if n==5 answer
12
2 2 3 1 2 4 2 3 5 3 4 5

Edited by author 14.02.2016 15:53

Edited by author 14.02.2016 15:53
Re: why this algo is wrong
Posted by Jane Soboleva (SumNU) 14 Feb 2016 16:22
Here's a simple program testing your answer. It outputs all the possible paths when the figure is still not found. You can modify constants in the header to test another one.

program test1789;
const nmoves = 12;
      nwidth = 5;
      mv: array[1..nmoves] of longint = (2, 2, 3, 1, 2, 4, 2, 3, 5, 3, 4, 5);
var i: longint;
    path: array[0..nmoves] of longint;
procedure Solve(v, z: longint);
var q: longint;
begin
    if (v < 1) or (v > nwidth) then exit;
    if z > nmoves then begin
        for q:=0 to nmoves do write(path[q], ' '); writeln;
    end else begin
        //if (v < 1) or (v > nwidth) then exit;
        if v = mv[z] then exit;
        path[z]:=v - 1;
        Solve(v - 1, z + 1);
        path[z]:=v + 1;
        Solve(v + 1, z + 1);
    end;
end;
begin
    for i:=1 to nwidth do begin
        path[0]:=i;
        Solve(i, 1);
    end;
end.

UPD: A small fix, moving one line into a proper place.

Edited by author 14.02.2016 16:28
Re: why this algo is wrong
Posted by nomercy 14 Feb 2016 17:17
thanks