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

wa in test#20
Posted by panyong0202 7 Jan 2009 08:11
Any Hint?
Re: wa in test#20
Posted by Aleksander 1 Apr 2009 15:08
I also have wa#20
Where's mistake?
But you've solved it, maybe you'll help me?
var i,n:integer;
cx,cy,x1,y1,x2,y2,x3,y3,x4,y4:integer;
x,y:array[1..102]of integer;
h,min,zn,ras1,ras2:real;
f:boolean;
begin
read(cx);read(cy);readln(n);
for i:=1 to n do readln(x[i],y[i]);
x[n+1]:=x[1];y[n+1]:=y[1];
f:=true;
zn:=0;
for i:=1 to n do begin
x1:=x[i]-cx;y1:=y[i]-cy;
x2:=x[i+1]-cx;y2:=y[i+1]-cy;
  if (zn=0)then begin
  zn:=x1*y2-x2*y1;
    if (zn=0)then begin
    if ((x[i]<=cx)and(cx<=x[i+1]))or((x[i]>=cx)and(cx>=x[i+1]))then f:=true
    else f:=false;
    break;break;break;
    end;
  end
  else begin
    if (zn*(x1*y2-x2*y1)<0)then begin
    f:=false;
    break;break;break;
    end;
  end;
end;
if (f=true)then write('0.000')
else begin
min:=0;
f:=false;
  for i:=1 to n do begin
  x1:=cx-x[i];y1:=cy-y[i];x2:=x[i+1]-x[i];y2:=y[i+1]-y[i];x3:=cx-x[i+1];y3:=cy-y[i+1];x4:=x[i]-x[i+1];y4:=y[i]-y[i+1];
    if (x1*x2+y1*y2>0)and(x3*x4+y3*y4>0)then begin
    x1:=x[i]-cx;y1:=y[i]-cy;x2:=x[i+1]-cx;y2:=y[i+1]-cy;
    h:=(abs(x1*y2-x2*y1))/(sqrt(sqr(x[i+1]-x[i])+sqr(y[i+1]-y[i])));
    end
  else h:=0;
  ras1:=sqrt(sqr(cx-x[i])+sqr(cy-y[i]));ras2:=sqrt(sqr(cx-x[i+1])+sqr(cy-y[i+1]));
  if (ras2<ras1)then ras1:=ras2;
  if (ras1<h)or(h=0)then h:=ras1;
    if (f=false)or(h<min)then begin
    min:=h;
    f:=true;
    end;
  end;
write((2*min):0:3);
end;
end.