2017 ACM/ICPC Asia Regional Qingdao Online:1001:Apple(几何+JAVA大数)

Apple

                                                               Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
                                                                                            Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
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(T30) 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

思路:求出三点外接圆圆心然后判断一下即可。但是这题卡精度。没办法,我只有化简一下公式然后让队友用JAVA写过的。

import java.util.*;
import java.math.*;

public class Main{


    public static void main(String[] args) 
    {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        sc.hasNext();
        int T = sc.nextInt();
        for(int k = 0; k < T; k++)
        {
            BigInteger x1,x2,x3,y1,y2,y3,ox,oy,a,b,d,p,q,r,s;
            x1 = sc.nextBigInteger();
            y1 = sc.nextBigInteger();
            x2 = sc.nextBigInteger();
            y2 = sc.nextBigInteger();
            x3 = sc.nextBigInteger();
            y3 = sc.nextBigInteger();
            ox = sc.nextBigInteger();
            oy = sc.nextBigInteger();
            a = ( x1.multiply(x1).subtract(x2.multiply(x2)) ).add( y1.multiply(y1).subtract(y2.multiply(y2)) );
            b = ( x1.multiply(x1).subtract(x3.multiply(x3)) ).add( y1.multiply(y1).subtract(y3.multiply(y3)) );
            d = ( x1.multiply(x1).subtract(ox.multiply(ox)) ).add( y1.multiply(y1).subtract(oy.multiply(oy)) );
            
            p = ( a.multiply(y1.subtract(y3)).subtract(b.multiply(y1.subtract(y2))) ).multiply(x1.subtract(ox));
            r = ( a.multiply(x1.subtract(x3)).subtract(b.multiply(x1.subtract(x2))) ).multiply(y1.subtract(oy));
            
            q = ( y1.subtract(y3).multiply(x1.subtract(x2)) ).subtract( y1.subtract(y2).multiply(x1.subtract(x3)) );
            s = ( y1.subtract(y2).multiply(x1.subtract(x3)) ).subtract( y1.subtract(y3).multiply(x1.subtract(x2)) );
            BigInteger zuo = d.multiply(q).multiply(s);
            BigInteger you = p.multiply(s).add(r.multiply(q));
            int flag;
            if(q.multiply(s).compareTo(BigInteger.ZERO) > 0)
                flag = 1;
            else
                flag = 0;
            if(flag == 1)
            {
                if(zuo.compareTo(you) < 0)
                System.out.println("Accepted");
                else
                    System.out.println("Rejected");
            }
            else
            {
                if(zuo.compareTo(you) > 0)
                System.out.println("Accepted");
                else
                    System.out.println("Rejected");
            }
            
        }
    }
}



/*
a.add(b);          加法运算 
a.subtract(b);     减法运算
a.multiply(b);     乘法运算  
a.divide(b);       除法运算
a.mod(b);          取模运算

a.gcd(b);          最大公因数  
a.max(b);          最大值(a,b)  
a.min(b);          最小值(a,b)  
a.modPow(k, mod);  返回(a^k)%mod  
a.pow(b);
a.toString();      返回大整数的string型

System.out.println(a);  自带换行的输出  
System.out.print(a);    不自带换行的输出

Scanner sc = new Scanner(System.in);  
System.out.println(a);//自带换行的输出  
System.out.print(a);  //不自带换行的输出 

if(n.compareTo(BigInteger.ZERO)==0)  break;  
*/





你可能感兴趣的:(计算几何)