Discussion of Problem 1258. Pooldont add negative numbers to answer The C# solution fails test #4. Error: Runtime error (access violation). But in C++, exactly the same solution passed. Does test 4 in this problem contain correct data? Please Help. Is it possible to know the contents of test 4 Fyodor Menshiko, what means "Contains empty sequence."? Edited by author 12.09.2018 10:02 think the four edges as four mirror...... :) really good hint) thanx Just compute total chanhe in X and Y and then output hypotenuse. It can be shown pretty intuitively by reflecting triangles, thanks for the hint. 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 . readln(w,d); . If (w=0)or(d=0)then . begin . writeln('0.0000'); . Halt; . End; . {initialisation} . readln(x0,y0); . readln(x1,y1); . readln(way); . 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 It's not so simple as you think, but simple in real. Try this test 4 6 2 1 2 5 R --- Your answer is 4.0000, but write answer is 5.6569 Thanks, good test! Thanke you, Ozone, you realy helped me! I've got AC already. I had WA on 11th test first, but then i changed the size of char array from 1000 to 1001... That changed ny WA on AC!! Guess, the true size of array is 1001 in 11th test case. Can post my solution... Can you give me some test my program got WA 5 6 3 1 1 5 RB --- ANS: 8.4853 (0<=W,D<=1000) (0<x0<W, 0<y0<D) (0<x1<W, 0<y1<D) if w and d are 0 then no x or y can be taken. In fact this problem need high-accuracy calculating. For example 10 10 1 1 9 9 LRLRLRLRLRLRLRLRLR.... And what is the answer for this test? Why do we need high-accuracy calculating? #include <stdio.h> #include <math.h> #include <string.h> int X1,Y1,X2,Y2,W,D,X,Y; double P; int l,r,f,b,first_l,first_f,last_l,last_f,N; char c[10010]; int main() { int i; scanf("%d %d %d %d %d %d",&W,&D,&X1,&Y1,&X2,&Y2); scanf("%s",c); N=strlen(c); for (i=0; i<N; ++i) { if (c[i]=='L') { first_l=1; break; } if (c[i]=='R') { first_l=0; break; } } for (i=0; i<N; ++i) { if (c[i]=='L') last_l=1; if (c[i]=='R') last_l=0; } for (i=0; i<N; ++i) { if (c[i]=='F') { first_f=1; break; } if (c[i]=='B') { first_f=0; break; } } for (i=0; i<N; ++i) { if (c[i]=='F') last_f=1; if (c[i]=='B') last_f=0; } for (i=0; i<N; ++i) { if ((c[i]=='L') || (c[i]=='R')) l++; if ((c[i]=='F') || (c[i]=='B')) f++; } if (l>0) { X=(l-1)*W; if (first_l==1) X+=X1; else X+=W-X1; if (last_l==1) X+=X2; else X+=W-X2; } else X=X1-X2; if (f>0) { Y=(f-1)*D; if (first_f==1) Y+=Y1; else Y+=D-Y1; if (last_f==1) Y+=Y2; else Y+=D-Y2; } else Y=Y1-Y2; P=sqrt((double)X*X+Y*Y); printf("%.4lf",P); return 0; } I think problem is this: P=sqrt((double)X*X+Y*Y); In 12th test 'int' will oveflow during multiplication. Just think of __int64. #include <stdio.h> #include <math.h> int i,j,n,m,k; int w,d; int main() { int x0,y0,x1,y1; scanf ("%d%d%d%d%d%d",&w,&d,&x0,&y0,&x1,&y1); char c[10000]; scanf ("%s",c); for (i=0;c[i];i++) { if (c[i]=='F') y0=-y0; if (c[i]=='L') x0=-x0; if (c[i]=='B') y0=d+d-y0; if (c[i]=='R') x0=w+w-x0; } double dist=sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1)); printf ("%.4lf\n",dist); return 0; } You must replace sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1)); with sqrt((double)((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1))); Edited by author 25.08.2004 22:02 I think this problem is simple but I got WA#14. var w,d:real; l:real; lx,ly,x0,y0,x1,y1:real; ch:char; begin readln(w,d); readln(x0,y0); readln(x1,y1); lx:=x0-x1; ly:=y0-y1; while not eof do begin read(ch); case upcase(ch) of 'L':lx:=lx+2*x1; 'R':lx:=lx+2*(w-x1); 'F':ly:=ly+2*y1; 'B':ly:=ly+2*(d-y1); end; end; l:=sqrt(lx*lx+ly*ly); write(l:0:4); end. Oh AC now! Very stupid bug:) Can you give me some test my program got WA I can't believe that my program WA19. Can you give me some test? Thanks Where is the speed of Vasechcin? Is It very important? the Speed of Vasechkin is fixed in the text. But it is not given in the condition of task. help me...
|
|