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 1215. Exactness of Projectile Hit

I think my program is quite right,but it get WA!!!
Posted by Zhang Ruiwen 25 Oct 2002 15:38
{$A+,B-,D+,E+,F-,G-,I+,L+,N+,O-,P-,Q-,R-,S+,T-,V+,X+,Y+}
{$M 65520,0,655360}
type uu=record
        x,y:longint;
        end;
var zuob:array[1..101] of uu;
    n,i,b:integer;

a1,a2,b1,b2,c1,c2,x,y,x1,x2,y1,y2,xj,yj,xp,yp,ans,min,l1,l2:extended;

procedure xyz(a1,b1,c1,a2,b2,c2:extended;var x,y:extended);
begin
 x:=(b1*c2-b2*c1)/(a1*b2-a2*b1);
 y:=(c1*a2-c2*a1)/(a1*b2-a2*b1);
end;

function distan(x1,y1,x2,y2:extended):extended;
begin
 distan:=sqrt(abs(sqr(x1-x2))+abs(sqr(y1-y2)));
end;

begin
 readln(xp,yp,n);
 for i:=1 to n do readln(zuob[i].x,zuob[i].y);
 zuob[n+1]:=zuob[1];
 b:=0;
 for i:=1 to n do
 begin
  if (zuob[i].x-xp)*(zuob[i+1].y-yp)-(zuob[i].y-yp)*(zuob[i+1].x-xp)
>0 then b:=1;
 end;
 if b=0 then begin writeln('0.000'); halt; end;
 ans:=1e+10;
 for i:=1 to n do
 begin
     a1:=zuob[i].y-zuob[i+1].y;
     b1:=zuob[i].x-zuob[i+1].x;
     c1:=(zuob[i+1].y-zuob[i].y)*zuob[i+1].x+(zuob[i].x-zuob[i+1].x)
*zuob[i+1].y;
     a2:=-b1;
     b2:=a1;
     c2:=-(a2*xp+b2*yp);
     xyz(a1,b1,c1,a2,b2,c2,xj,yj);
{     xj:=(b1*c2-b2*c1)/(a1*b2-a2*b1);
     yj:=(c1*a2-c2*a1)/(a1*b2-a2*b1);}
     if ((zuob[i].x-xj)*(zuob[i+1].x-xj)<=0)and
     ((zuob[i].y-yj)*(zuob[i+1].y-yj)<=0) then
     min:=distan(xp,yp,xj,yj) else
     begin
      l1:=distan(xp,yp,zuob[i].x,zuob[i].y);
      if l1<1e-14 then l1:=0;
      l2:=distan(xp,yp,zuob[i+1].x,zuob[i+1].y);
      if l1<l2 then min:=l1
               else min:=l2;
     end;
     if min<ans then ans:=min;
 end;
 writeln(ans*2:0:3);
end.
I think your checking that point is outside the polygon is wrong. Here's a test (+)
Posted by shitty.Mishka 26 Oct 2002 03:17
Try this obvious test:
2 1 8
0 1
1 0
2 0
3 1
3 2
2 3
1 3
0 2

The answer should be 0.000

Good luck