| Help! WA! This is my source code. Have any ideas about why is it WA?
 {$N+}
 program Exactness_Of_Projectile_Hit;
 const  GMT=maxLongInt;
 type   point=record
 X:LongInt;
 Y:LongInt;
 end;
 line=record
 A:real;
 B:real;
 C:real;
 end;
 var    Points:array[1..102] of point;
 Lines:array[1..102] of line;
 ans,AB,BC,AC,X,X1,Y1,X2,Y2:extended;
 N,i:LongInt;
 dop,dop1,Xv,Yv:extended;
 plus,minus:boolean;
 procedure Quit;
 begin
 writeln(0);
 halt;
 end;
 function min(a,b:extended):extended;
 begin
 if a>b then
 min:=b else
 min:=a;
 end;
 function dist(a,b,c,d:extended):extended;
 begin
 dop:=sqr(a-b);
 dop1:=sqr(c-d);
 dist:=sqrt(dop+dop1);
 end;
 begin
 ans:=GMT;
 readln(Xv,Yv,N);
 for i:=1 to N do
 readln(Points[i].X,Points[i].Y);
 {Checking if (Xv;Yv) is inside}
 Points[N+1]:=Points[1];
 for i:=1 to N do
 begin
 Lines[i].A:=Points[i+1].y-Points[i].y;
 Lines[i].B:=Points[i].x-Points[i+1].x;
 Lines[i].C:=Points[i].x*Points[i+1].y-Points[i].y*Points
 [i+1].x;
 end;
 plus:=false;
 minus:=false;
 for i:=1 to N do
 begin
 if Lines[i].A*Xv+Lines[i].B*Yv>Lines[i].C then
 plus:=true else
 if Lines[i].A*Xv+Lines[i].B*Yv<Lines[i].C then
 minus:=true;
 end;
 if not (plus and minus) then
 Quit else
 {Counting the distance}
 begin
 for i:=1 to N do
 begin
 X1:=Points[i].x;
 X2:=Points[i+1].x;
 Y1:=Points[i].Y;
 Y2:=Points[i+1].Y;
 AB:=dist(x1,x2,y1,y2);
 BC:=dist(Xv,x2,Yv,Y2);
 AC:=dist(Xv,X1,Yv,Y1);
 X:=(sqr(AC)-sqr(BC)-sqr(AB))/(-2*AB);
 if (X>=0) and (x<=AB) then
 ans:=min(ans,sqrt(sqr(BC)-sqr(X)));
 end;
 for i:=1 to N do
 begin
 X1:=Points[i].X;
 Y1:=Points[i].Y;
 ans:=min(ans,dist(X1,Xv,Y1,Yv));
 end;
 end;
 writeln(ans*2:0:3);
 end.
Thanks, I got AC. > This is my source code. Have any ideas about why is it WA?>
 > {$N+}
 > program Exactness_Of_Projectile_Hit;
 > const  GMT=maxLongInt;
 > type   point=record
 >                    X:LongInt;
 >                    Y:LongInt;
 >              end;
 >        line=record
 >                    A:real;
 >                    B:real;
 >                    C:real;
 >             end;
 > var    Points:array[1..102] of point;
 >        Lines:array[1..102] of line;
 >        ans,AB,BC,AC,X,X1,Y1,X2,Y2:extended;
 >        N,i:LongInt;
 >        dop,dop1,Xv,Yv:extended;
 >        plus,minus:boolean;
 > procedure Quit;
 > begin
 >      writeln(0);
 >      halt;
 > end;
 > function min(a,b:extended):extended;
 > begin
 >      if a>b then
 >          min:=b else
 >          min:=a;
 > end;
 > function dist(a,b,c,d:extended):extended;
 > begin
 >      dop:=sqr(a-b);
 >      dop1:=sqr(c-d);
 >      dist:=sqrt(dop+dop1);
 > end;
 > begin
 >      ans:=GMT;
 >      readln(Xv,Yv,N);
 >      for i:=1 to N do
 >         readln(Points[i].X,Points[i].Y);
 >      {Checking if (Xv;Yv) is inside}
 >      Points[N+1]:=Points[1];
 >      for i:=1 to N do
 >      begin
 >           Lines[i].A:=Points[i+1].y-Points[i].y;
 >           Lines[i].B:=Points[i].x-Points[i+1].x;
 >           Lines[i].C:=Points[i].x*Points[i+1].y-Points[i].y*Points
 > [i+1].x;
 >      end;
 >      plus:=false;
 >      minus:=false;
 >      for i:=1 to N do
 >      begin
 >           if Lines[i].A*Xv+Lines[i].B*Yv>Lines[i].C then
 >               plus:=true else
 >           if Lines[i].A*Xv+Lines[i].B*Yv<Lines[i].C then
 >               minus:=true;
 >      end;
 >      if not (plus and minus) then
 >         Quit else
 >      {Counting the distance}
 >      begin
 >           for i:=1 to N do
 >           begin
 >                X1:=Points[i].x;
 >                X2:=Points[i+1].x;
 >                Y1:=Points[i].Y;
 >                Y2:=Points[i+1].Y;
 >                AB:=dist(x1,x2,y1,y2);
 >                BC:=dist(Xv,x2,Yv,Y2);
 >                AC:=dist(Xv,X1,Yv,Y1);
 >                X:=(sqr(AC)-sqr(BC)-sqr(AB))/(-2*AB);
 >                if (X>=0) and (x<=AB) then
 >                   ans:=min(ans,sqrt(sqr(BC)-sqr(X)));
 >           end;
 >           for i:=1 to N do
 >           begin
 >                X1:=Points[i].X;
 >                Y1:=Points[i].Y;
 >                ans:=min(ans,dist(X1,Xv,Y1,Yv));
 >           end;
 >      end;
 >      writeln(ans*2:0:3);
 > end.
Re: Thanks, I got AC. What sort of modifications did you make to your code |