Apple HDU - 6206(JAVA高精度求三角形外心)

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");
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值