zoukankan      html  css  js  c++  java
  • HDU 6205[计算几何,JAVA]

    题目链接【http://acm.hdu.edu.cn/showproblem.php?pid=6206】

    题意:

      给出不共线的三个点,和一个点(x,y),然后判断(x,y)在不在这三个点组成的圆外。

    题解:

      咋一看很简单,实际也很简单,但是坐标都很大,会爆long double,怎么办?只有用java了。

    公式:

    a = ((y2 - y1) * (y3 * y3 - y1 * y1 + x3 * x3 - x1 * x1) - (y3 - y1) * (y2 * y2 - y1 * y1 + x2 * x2 - x1 * x1)) / (2.0 * ((x3 - x1) * (y2 - y1) - (x2 - x1) * (y3 - y1)));
    b = ((x2 - x1) * (x3 * x3 - x1 * x1 + y3 * y3 - y1 * y1) - (x3 - x1) * (x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1)) / (2.0 * ((y3 - y1) * (x2 - x1) - (y2 - y1) * (x3 - x1)));
    r ^ 2 = (x1 - a) * (x1 - a) + (y1 - b) * (y1 - b);
    

      

    import java.util.Scanner;
    import java.math.BigDecimal;
    import java.io.BufferedInputStream;
    
    public class Main {
    
        public static void main(String[] args) {
            Scanner cin = new Scanner(new BufferedInputStream(System.in));
            BigDecimal x1, y1, x2, y2, x3, y3, x, y;
            int T = cin.nextInt();
            for (int k = 1; k <= T; k++) {
                x1 = cin.nextBigDecimal();
                y1 = cin.nextBigDecimal();
                x2 = cin.nextBigDecimal();
                y2 = cin.nextBigDecimal();
                x3 = cin.nextBigDecimal();
                y3 = cin.nextBigDecimal();
                x = cin.nextBigDecimal();
                y = cin.nextBigDecimal();
    
                BigDecimal t1 = y2.subtract(y1);
                BigDecimal t2 = y3.multiply(y3);
                t2 = t2.subtract(y1.multiply(y1));
                t2 = t2.add(x3.multiply(x3));
                t2 = t2.subtract(x1.multiply(x1));
                BigDecimal t3 = y3.subtract(y1);
                BigDecimal t4 = y2.multiply(y2);
                t4 = t4.subtract(y1.multiply(y1));
                t4 = t4.add(x2.multiply(x2));
                t4 = t4.subtract(x1.multiply(x1));
                BigDecimal t5 = (x3.subtract(x1)).multiply(y2.subtract(y1));
                t5 = t5.subtract(x2.subtract(x1).multiply(y3.subtract(y1)));
                t5 = t5.multiply(BigDecimal.valueOf(2.0));
                BigDecimal a = ((t1.multiply(t2)).subtract(t3.multiply(t4))).divide(t5);
    
    
                t1 = x2.subtract(x1);
                t3 = x3.subtract(x1);
                t5 = (y3.subtract(y1)).multiply(x2.subtract(x1));
                t5 = t5.subtract(y2.subtract(y1).multiply(x3.subtract(x1)));
                t5 = t5.multiply(BigDecimal.valueOf(2.0));
                BigDecimal b = ((t1.multiply(t2)).subtract(t3.multiply(t4))).divide(t5);
                BigDecimal r = (x1.subtract(a)).multiply(x1.subtract(a));
                r = r.add((y1.subtract(b)).multiply(y1.subtract(b)));
    
                BigDecimal R = (x.subtract(a)).multiply(x.subtract(a));
                R = R.add((y.subtract(b)).multiply(y.subtract(b)));
                if(R.compareTo(r) > 0) {
                    System.out.println("Accepted");
                }
                else {
                    System.out.println("Rejected");
                }
            }
        }
    }
    

      

  • 相关阅读:
    c++命名规范与代码风格
    subline的多行游标快捷键
    selenium中的action
    Fiddler 教程(转)
    java.util.NoSuchElementException解决办法
    http协议中的URI
    深入研究java.lang.Runtime类(转)
    深入研究java.lang.Process类(转)
    java调用autoit3脚本
    AutoIT转
  • 原文地址:https://www.cnblogs.com/pealicx/p/7541826.html
Copyright © 2011-2022 走看看