Apple HDU - 6206
Apple is Taotao’s favourite fruit. In his backyard, there are three apple trees with coordinates (x1,y1), (x2,y2), and (x3,y3). Now Taotao is planning to plant a new one, but he is not willing to take these trees too close. He believes that the new apple tree should be outside the circle which the three apple trees that already exist is on. Taotao picked a potential position (x,y)
of the new tree. Could you tell him if it is outside the circle or not?
Input
The first line contains an integer T, indicating that there are T(T≤30) cases.
In the first line of each case, there are eight integers x1,y1,x2,y2,x3,y3,x,y, as described above.
The absolute values of integers in input are less than or equal to 1,000,000,000,000
.
It is guaranteed that, any three of the four positions do not lie on a straight line.
Output
For each case, output “Accepted” if the position is outside the circle, or “Rejected” if the position is on or inside 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
Accepted
Rejected
Rejected
题意:
给定四个点坐标,问最后一个点在前三个点构成的三角形的外接圆的园内还是圆外
分析:

因为每个数的绝对值是1e12所以再求距离的时候一定会有平方变成1e24,所以要用java高精度
code:
import java.util.*;
import java.math.*;
public class Main
{
public static BigDecimal fun(BigDecimal x)
{
return x.multiply(x);
}
public static void main(String []args)
{
Scanner in = new Scanner(System.in);
int Tcase = in.nextInt();
// System.out.println(Tcase);
while ( (Tcase --) > 0 )
{
BigDecimal
x1 = in.nextBigDecimal() ,y1 = in.nextBigDecimal(),
x2 = in.nextBigDecimal() ,y2 = in.nextBigDecimal(),
x3 = in.nextBigDecimal() ,y3 = in.nextBigDecimal(),
x4 = in.nextBigDecimal() ,y4 = in.nextBigDecimal();
BigDecimal a = y3.subtract(y2).multiply(new BigDecimal(2) ).multiply( x2.multiply(x2).add(y2.multiply(y2)) .subtract( x1.multiply(x1)).subtract( y1.multiply(y1)));
BigDecimal b = y2.subtract(y1).multiply(new BigDecimal(2)).multiply( x3.multiply(x3).add( y3.multiply(y3)).subtract( x2.multiply(x2)).subtract(y2.multiply(y2)));
BigDecimal c = y3.subtract(y2).multiply(new BigDecimal(4)).multiply(x2.subtract(x1));
BigDecimal d = y2.subtract(y1).multiply(new BigDecimal(4)).multiply(x3.subtract(x2));
BigDecimal x = a.subtract(b).divide(c.subtract(d));
// System.out.println(a + " " + b + " " + c + " " + d );
a = x3.subtract(x2).multiply(new BigDecimal(-2)).multiply( x2.multiply(x2).add( y2.multiply(y2)).subtract(x1.multiply(x1)).subtract( y1.multiply(y1)));
b = x2.subtract(x1).multiply(new BigDecimal(2)).multiply( x3.multiply(x3).add(y3.multiply(y3)).subtract(x2.multiply(x2)).subtract( y2.multiply(y2)));
c = y3.subtract(y2).multiply(new BigDecimal(4)).multiply(x2.subtract(x1));
d = y2.subtract(y1).multiply(new BigDecimal(4)).multiply(x3.subtract(x2));
BigDecimal y = a.add(b).divide(c.subtract(d));
BigDecimal r = fun(x.subtract(x1)).add( fun(y.subtract(y1)) );
BigDecimal temp = fun(x.subtract(x4)).add(fun(y.subtract(y4)) );
// System.out.println(x + " " + y);
if(temp.compareTo(r) == 1)System.out.println("Accepted");
else System.out.println("Rejected");
}
}
}

本文介绍了一种算法,用于判断给定点是否位于由三个已知点形成的圆的外部。通过解析输入数据,利用高精度计算避免数值溢出,最终确定点的位置关系。
429

被折叠的 条评论
为什么被折叠?



