Apple
Time limit:1000/1000 MS (java/others) Memory limit:65535/32768 K (java/others)
Total submission (s): 806 Accepted Submission (s): 267
Problem descriptionapple is Taotao ' s favourite fruit. In his backyard, there is three apple trees with coordinates(x1,y1) ,(x2,y2) , and(x3,y3) . Now Taotao was planning to plant a new one, but he was not willing to take these trees too close. He believes that the new Apple tree should was outside the circle which the three apple trees that already exist are on. Taotao picked a potential position (x,y) of the new tree. Could you tell him if it's outside the circle or not?
Inputthe first line contains an integerT, indicating that there isT(t≤) Cases.
In the first line of all case, there is eight integersX1,Y1, x2 , Y2,x3,y 3, X,y , as described above.
The absolute values of integers in input is less than or equal to 1 , A. .
It is guaranteed this, any three of the four positions does not lie on a straight line.
Outputfor each case, output "Accepted" if the position is outside the circle, or "rejected" if the position are on or insid E The circle.
Sample Input
3-2 0 0-2 2 0 2-2-2 0 0-2 2 0 0 2-2 0 0-2 2 0 1 1
Sample Output
acceptedrejectedrejected
Just enter the coordinates of three points to P1 (x1,y1) P2 (x2,y2) P3 (x3,y3) a=x1*x1+y1*y1 b=x2*x2+y2*y2c=x3*x3+y3*y3g= (y3-y2) *x1+ (y1-y3) * x2+ (Y2-y1) *x3x= ((b-c) *y1+ (c-a) *y2+ (A-B) *y3)/(2*g) y= ((c-b) *x1+ (a-c) *x2+ (b-a) *x3)/(2*G)
Import Java.math.bigdecimal;import Java.util.scanner;public class Main {public static void main (string[] args) { Scanner cin=new Scanner (system.in); BigDecimal a,b,c,g; BigDecimal x1,x2,x3,y1,y2,y3,x0,y0; BigDecimal x, y; int t; T=cin.nextint (); while (t-->0) {x1=cin.nextbigdecimal (); Y1=cin.nextbigdecimal (); X2=cin.nextbigdecimal (); Y2=cin.nextbigdecimal (); X3=cin.nextbigdecimal (); Y3=cin.nextbigdecimal (); X0=cin.nextbigdecimal (); Y0=cin.nextbigdecimal (); A=x1.multiply (x1). Add (y1.multiply (y1)); B=x2.multiply (x2). Add (Y2.multiply (y2)); C=x3.multiply (x3). Add (Y3.multiply (y3)); G=bigdecimal.valueof (1); G=y3.subtract (y2). Multiply (x1). Add (Y1.subtract (y3). Multiply (x2)). Add (Y2.subtract (y1). Multiply (x3)); X=b.subtract (C). Multiply (y1). Add (C.subtract (A). Multiply (y2)). Add (A.subtract (B). Multiply (Y3)). Divide (bigdecimal.valueof (2)); Y=c.subtract (B). Multiply (x1). Add (A.subtract (C). Multiply (x2)). Add (B.subtract (A). Multiply (x3)). Divide ( Bigdecimal.valueof (2)); X0=x0.multiply (G); Y0=y0.multiply (G); X1=x1.multiply (G); Y1=y1.multiply (G); BigDecimal a=x0.subtract (x). Multiply (X0.subtract (x)). Add (Y0.subtract (y). Multiply (Y0.subtract (y))); BigDecimal b=x1.subtract (x). Multiply (X1.subtract (x)). Add (Y1.subtract (y). Multiply (Y1.subtract (y))); if (A.compareto (b) >0) System.out.println ("Accepted"); Else System.out.println ("rejected"); } }}
POJ 6206 Apple