|
|
вернуться в форумHelp me to fix my program. My program gives WA on test 11. Help me to fix some bugs thanks a lot. {$N+} Program ExactnessOfProjectileHit; Const Epsilon=0.00000000000001; Type Real=Extended; Type Point=Record X,Y:Real; End; Var Circle:Point; Polygon:Array[1..100] Of Point;VerticesCount:Byte; I,J:Byte; Result:Real; Procedure ReadData; Begin ReadLn(Circle.X,Circle.Y,VerticesCount); For I:=1 To VerticesCount Do ReadLn(Polygon[I].X,Polygon[I].Y); End; Procedure Solve; Function Min(A,B:Real):Real; Begin If A<B Then Min:=A Else Min:=B; End; Function PointIsInPolygon:Boolean; Var Index:Byte; TrueSquare,Square:Real; Begin TrueSquare:=0; For Index:=2 To VerticesCount-1 Do TrueSquare:=TrueSquare+(Polygon[Index].X-Polygon[1].X)*(Polygon[Index+1].Y-Polygon[1].Y)- (Polygon[Index+1].X-Polygon[1].X)*(Polygon[Index].Y-Polygon[1].Y); TrueSquare:=Abs(TrueSquare)/2; Square:=0; For Index:=1 To VerticesCount-1 Do Square:=Square+Abs((Polygon[Index].X-Circle.X)*(Polygon[Index+1].Y-Circle.Y)- (Polygon[Index+1].X-Circle.X)*(Polygon[Index].Y-Circle.Y)); Square:=Square+Abs((Polygon[VerticesCount].X-Circle.X)*(Polygon[1].Y-Circle.Y)- (Polygon[1].X-Circle.X)*(Polygon[VerticesCount].Y-Circle.Y)); Square:=Abs(Square)/2; PointIsInPolygon:=Abs(Square-TrueSquare)<Epsilon; End; Function Distance(P1,P2:Point):Real; Begin Distance:=Sqrt(Sqr(P1.X-P2.X)+Sqr(P1.Y-P2.Y)); End; Function GetShortestDistance(P1,P2,P3:Point):Real; Var TmpReal,TmpReal2:Real; TmpPoint:Point; Begin TmpReal:=(P1.X-P2.X);TmpReal2:=(P2.Y-P1.Y); If TmpReal2<>0 Then Begin TmpPoint.Y:=((P2.X-P3.X)*TmpReal*TmpReal2)+(P3.Y*Sqr(TmpReal2))+(P2.Y*Sqr(TmpReal)); TmpPoint.Y:=TmpPoint.Y/(Sqr(TmpReal)+Sqr(TmpReal2)); TmpPoint.X:=(((P2.Y-TmpPoint.Y)*TmpReal)/TmpReal2)+P2.X; End Else Begin TmpPoint.X:=P3.X; TmpPoint.Y:=P1.Y; End; If P1.Y<=P2.Y Then Begin If (TmpPoint.Y>=P1.Y) And (TmpPoint.Y<=P2.Y) Then Begin GetShortestDistance:=Distance(P3,TmpPoint); End Else Begin GetShortestDistance:=Min(Distance(P1,P3),Distance(P2,P3)); End; End Else Begin If (TmpPoint.Y>=P2.Y) And (TmpPoint.Y<=P1.Y) Then Begin GetShortestDistance:=Distance(P3,TmpPoint); End Else Begin GetShortestDistance:=Min(Distance(P1,P3),Distance(P2,P3)); End; End; End; Begin If PointIsInPolygon=False Then Begin Result:=GetShortestDistance(Polygon[1],Polygon[VerticesCount],Circle); For I:=1 To VerticesCount-1 Do Result:=Min(Result,GetShortestDistance(Polygon[I],Polygon[I+1],Circle)); Result:=Result*2; End Else Result:=0; End; Procedure WriteData; Begin WriteLn(Result:0:3); End; Begin ReadData; Solve; WriteData; End. |
|
|