|
|
вернуться в форум(WA) What's wrong with my program? VAR X0, X1, X2 : Extended; Y0, Y1, Y2 : Extended; A, B, C : Extended; A0, B0, C0 : Extended; A1, B1, C1 : Extended; CX, CY, R : Extended; MinX, MaxX, MinY, MaxY : Extended; FUNCTION MyRoundA(A : Extended) : Extended; BEGIN IF Trunc(A) = A THEN MyRoundA := A ELSE MyRoundA := Trunc(A)+1 END; FUNCTION MyRoundB(A : Extended) : Extended; BEGIN IF Trunc(A) = A THEN MyRoundB := A ELSE MyRoundB := Trunc(A)-1 END; BEGIN ReadLn(X0, Y0); ReadLn(X1, Y1); ReadLn(X2, Y2); MinX := X0; IF MinX > X1 THEN MinX := X1; MaxX := X0; IF MaxX < X1 THEN MaxX := X1; MinY := Y0; IF MinY > Y1 THEN MinY := Y1; MaxY := Y0; IF MaxY < Y1 THEN MaxY := Y1; CX := (X0+X1)/2; CY := (Y0+Y1)/2; A := (Y1-Y0); B := (X0-X1); C := X1*Y0-X0*Y1; IF (A <> 0) THEN BEGIN A0 := B/A; B0 := -1; C0 := CY-A0*CX; END ELSE BEGIN A0 := 1; B0 := 0; C0 := -CX; END; CX := (X0+X2)/2; CY := (Y0+Y2)/2; A := (Y2-Y0); B := (X0-X2); C := X2*Y0-X0*Y2; IF (A <> 0) THEN BEGIN A1 := B/A; B1 := -1; C1 := CY-A1*CX; END ELSE BEGIN A1 := 1; B1 := 0; C1 := -CX; END; {center} CX := (B0*C1-B1*C0)/(A0*B1-A1*B0); CY := (A1*C0-A0*C1)/(A0*B1-A1*B0); {radius} R := Sqrt(Sqr(X0-CX)+Sqr(Y0-CY)); {Line (X0,Y0) to (X1,Y1)} A := (Y1-Y0); B := (X0-X1); C := X1*Y0-X0*Y1; IF (A*X2+B*Y2+C)*(A*(CX-R)+B*CY+C) >= 0 THEN MinX := CX-R; IF (A*X2+B*Y2+C)*(A*(CX+R)+B*CY+C) >= 0 THEN MaxX := CX+R; IF (A*X2+B*Y2+C)*(A*CX+B*(CY-R)+C) >= 0 THEN MinY := CY-R; IF (A*X2+B*Y2+C)*(A*CX+B*(CY+R)+C) >= 0 THEN MaxY := CY+R; MinX := MyRoundB(MinX); MaxX := MyRoundA(MaxX); MinY := MyRoundB(MinY); MaxY := MyRoundA(MaxY); IF MinX < -1000 THEN MinX := -1000; IF MinY < -1000 THEN MinY := -1000; IF MaxX > 1000 THEN MaxX := 1000; IF MaxY > 1000 THEN MaxY := 1000; Write((MaxX-MinX)*(MaxY-MinY):0:0); END. Why my program still WA? Please help me! Thank you! {$N+} {$E-} VAR X0, X1, X2 : Extended; Y0, Y1, Y2 : Extended; A, B, C : Extended; A0, B0, C0 : Extended; A1, B1, C1 : Extended; CX, CY, R : Extended; MinX, MaxX, MinY, MaxY : Extended; FUNCTION MyRoundUp(A : Extended) : Extended; BEGIN IF Trunc(A) = A THEN MyRoundUp := Trunc(A) ELSE IF A > 0 THEN MyRoundUp := Trunc(A+1) ELSE MyRoundUp := Trunc(A) END; FUNCTION MyRoundDown(A : Extended) : Extended; BEGIN IF Trunc(A) = A THEN MyRoundDown := Trunc(A) ELSE IF A < 0 THEN MyRoundDown := Trunc(A-1) ELSE MyRoundDown := Trunc(A); END; BEGIN ReadLn(X0, Y0); ReadLn(X1, Y1); ReadLn(X2, Y2); MinX := X0; IF MinX > X1 THEN MinX := X1; MaxX := X0; IF MaxX < X1 THEN MaxX := X1; MinY := Y0; IF MinY > Y1 THEN MinY := Y1; MaxY := Y0; IF MaxY < Y1 THEN MaxY := Y1; CX := (X0+X1)/2; CY := (Y0+Y1)/2; {Line (X0,Y0) to (X1,Y1)} A := (Y1-Y0); B := (X0-X1); C := X1*Y0-X0*Y1; IF (Y1 <> Y0) THEN BEGIN A0 := B/A; B0 := -1; C0 := CY-A0*CX; END ELSE BEGIN A0 := 1; B0 := 0; C0 := -CX; END; CX := (X0+X2)/2; CY := (Y0+Y2)/2; {Line (X0,Y0) to (X2,Y2)} A := (Y2-Y0); B := (X0-X2); C := X2*Y0-X0*Y2; IF (Y2 <> Y0) THEN BEGIN A1 := B/A; B1 := -1; C1 := CY-A1*CX; END ELSE BEGIN A1 := 1; B1 := 0; C1 := -CX; END; {center} CX := (B0*C1-B1*C0)/(A0*B1-A1*B0); CY := (A1*C0-A0*C1)/(A0*B1-A1*B0); {radius} R := Sqrt(Sqr(X0-CX)+Sqr(Y0-CY)); {Line (X0,Y0) to (X1,Y1)} A := (Y1-Y0); B := (X0-X1); C := X1*Y0-X0*Y1; IF (A*X2+B*Y2+C)*(A*(CX-R)+B*CY+C) > 0 THEN MinX := CX-R; IF (A*X2+B*Y2+C)*(A*(CX+R)+B*CY+C) > 0 THEN MaxX := CX+R; IF (A*X2+B*Y2+C)*(A*CX+B*(CY-R)+C) > 0 THEN MinY := CY-R; IF (A*X2+B*Y2+C)*(A*CX+B*(CY+R)+C) > 0 THEN MaxY := CY+R; MaxX := MyRoundUp(MaxX); MaxY := MyRoundUp(MaxY); MinX := MyRoundDown(MinX); MinY := MyRoundDown(MinY); Write((MaxX-MinX)*(MaxY-MinY):0:0); END. |
|
|