ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1258. Pool

I had WA on test #2. Why did it happened? Help me, please.
Posted by \$T.MAX 5 Aug 2005 20:02
Here's my code:
(I looked for the walls like as mirrors)

{H+}{N+}
.Program N1258;
.
.var
.   w,d           :integer;
.   x1,x0,y1,y0   :integer;
.   way           :string;
.   leng          :integer;
.   BF,LR         :integer;
.   hor,ver       :integer;
.   i,j           :integer;
.   lastBF,lastLR,firstBF,firstLR :char;
.   Lx,Ly,Lzag    :extended;
.
.BEGIN
.   If (w=0)or(d=0)then
.   begin
.      writeln('0.0000');
.      Halt;
.   End;
.   {initialisation}

.   If way='' then
.   Begin
.      writeln((sqrt(sqr(x0-x1)+sqr(y0-y1))):0:4);
.      Halt;
.   End;

.   Leng:=length(way);

.   firstBF:='0';
.   firstLR:='0';

.   {finding last and first of B and F}
.   {finding number of B and F}
.   For i:=1 to leng do
.      If (way[i]='B')or(way[i]='F')then
.      Begin
.         lastBF:=way[i];
.         IF firstBF='0' then
.            firstBF:=way[i];
.         inc(BF);
.      End;

.   {finding last and first of L and R}
.   {finding number of  L and R}
.   For i:=1 to leng do
.      If (way[i]='L')or(way[i]='R')then
.      Begin
.         lastLR:=way[i];
.         IF firstLR='0' then
.            firstLR:=way[i];
.         inc(LR);
.      End;

.   {finding length of route}
.   IF firstBF='B' then
.      Ly:=d-y0
.       else Ly:=y0;
.   IF firstLR='L' then
.      Lx:=x0
.       else Lx:=w-x0;
.   IF lastBF='B' then
.      Ly:=Ly+d-y1
.       else Ly:=Ly+y1;
.   IF lastLR='L' then
.      Lx:=Lx+x1
.       else Lx:=Lx+w-x1;
.   Lx:=Lx+w*(LR-1);
.   Ly:=Ly+d*(BF-1);
.   Lzag:=sqrt(Lx*Lx+Ly*Ly);
.   Writeln(Lzag:0:4);
.END.

PS. Ican't see the difference between AC code from forum.

Edited by author 20.08.2005 02:34
Re: I had WA on test #2. Why did it happened? Help me, please.
Posted by Loky 10 Aug 2006 08:49
It's not so simple as you think, but simple in real.
Try this test
4 6
2 1
2 5
R
---