|  | 
|  | 
| back to board | Re: wa in test#20 I also have wa#20Where'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.
 | 
 | 
|