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

判断给定一点是否在三角形外接圆内。

给定三角形三个顶点的坐标,如何求三角形的外心的坐标呢?

知乎链接:https://www.zhihu.com/question/40422123/answer/86514178

例如 :给定a(x1,y1) b(x2,y2) c(x3,y3)求外接圆心坐标O(x,y)

1. 首先,外接圆的圆心是三角形三条边的垂直平分线的交点,我们根据圆心到顶点的距离相等,可以列出以下方程:
(x1-x)*(x1-x)+(y1-y)*(y1-y)=(x2-x)*(x2-x)+(y2-y)*(y2-y);
(x2-x)*(x2-x)+(y2-y)*(y2-y)=(x3-x)*(x3-x)+(y3-y)*(y3-y);

2.化简得到:
2*(x2-x1)*x+2*(y2-y1)y=x2^2+y2^2-x1^2-y1^2;
2*(x3-x2)*x+2*(y3-y2)y=x3^2+y3^2-x2^2-y2^2;

令:A1=2*(x2-x1);
B1=2*(y2-y1);
C1=x2^2+y2^2-x1^2-y1^2;
A2=2*(x3-x2);
B2=2*(y3-y2);
C2=x3^2+y3^2-x2^2-y2^2;
即:A1*x+B1y=C1;
A2*x+B2y=C2;

3.最后根据克拉默法则:
x=((C1*B2)-(C2*B1))/((A1*B2)-(A2*B1));
y=((A1*C2)-(A2*C1))/((A1*B2)-(A2*B1));

所以x,y为圆心坐标。

然后最后r^2  = (x1-x)*(x1-x)+(y1-y)*(y1-y)就好了。

C++卡double,换成Java写,用BigDecimal写。

 import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*; public class Main { final static BigInteger HUNDRED = BigInteger.valueOf(100); //叉乘求面积
/* private static BigDecimal TriangleArea(POINT pi,POINT pj,POINT pk)
{
BigDecimal num1 = (pj.x.subtract(pi.x)).multiply(pk.y.subtract(pi.y));
BigDecimal num2 = (pk.x.subtract(pi.x)).multiply(pj.y.subtract(pi.y));
BigDecimal num3 = (num1.subtract(num2)).abs();
BigDecimal two = new BigDecimal("2.0");
return num3.divide(two);
}*/
//平方
private static BigDecimal pinfang(BigDecimal x)
{
return x.multiply(x);
} //求长度
private static BigDecimal Dis(POINT a,POINT b)
{
return pinfang(a.x.subtract(b.x)).add(pinfang(a.y.subtract(b.y)));
} public static void main(String[] args) {
// TODO 自动生成的方法存根
Scanner cin=new Scanner(System.in);
int T = cin.nextInt();
for(int i=1;i<=T;i++)
{
POINT A = new POINT();
POINT B = new POINT();
POINT C = new POINT();
POINT D = new POINT(); A.x = cin.nextBigDecimal();
A.y = cin.nextBigDecimal();
B.x = cin.nextBigDecimal();
B.y = cin.nextBigDecimal();
C.x = cin.nextBigDecimal();
C.y = cin.nextBigDecimal();
D.x = cin.nextBigDecimal();
D.y = cin.nextBigDecimal(); BigDecimal two = new BigDecimal("2.0");
BigDecimal four = new BigDecimal("4.0"); //求圆心
BigDecimal c1 = ((pinfang(A.x).add(pinfang(A.y))).subtract(pinfang(B.x).add(pinfang(B.y)))).divide(two);
BigDecimal c2 = ((pinfang(A.x).add(pinfang(A.y))).subtract(pinfang(C.x).add(pinfang(C.y)))).divide(two); POINT center = new POINT();
center.x = (c1.multiply((A.y.subtract(C.y)))).subtract(c2.multiply(A.y.subtract(B.y)));
BigDecimal tmp = ((A.x.subtract(B.x)).multiply(A.y.subtract(C.y))).subtract((A.x.subtract(C.x)).
multiply(A.y.subtract(B.y)));
center.x = center.x.divide(tmp);
center.y = (c1.multiply((A.x.subtract(C.x)))).subtract(c2.multiply(A.x.subtract(B.x)));
tmp = ((A.y.subtract(B.y)).multiply(A.x.subtract(C.x))).subtract((A.y.subtract(C.y)).
multiply(A.x.subtract(B.x)));
center.y = center.y.divide(tmp);
//求半径
BigDecimal r2 = pinfang(A.x.subtract(center.x)).add(pinfang(A.y.subtract(center.y)));
//圆心到D点距离
BigDecimal tempr = pinfang(D.x.subtract(center.x)).add(pinfang(D.y.subtract(center.y))); if(tempr.compareTo(r2)<=0)
{
System.out.println ("Rejected");
}
else
{
System.out.println ("Accepted");
}
}
}
} class POINT
{ BigDecimal x;
BigDecimal y;
} /*
41
0 0 1 1 2 0 2 0
-2 0 0 -2 2 0 2 -2
-2 0 0 -2 2 0 0 2
-2 0 0 -2 2 0 1 1
*/

HDU 6206 Apple的更多相关文章

  1. HDU 6206 Apple (高精确度+JAVA BigDecimal)

    Problem Description Apple is Taotao's favourite fruit. In his backyard, there are three apple trees ...

  2. HDU 6206 Apple【计算几何+高精度Java】

    Problem Description Apple is Taotao's favourite fruit. In his backyard, there are three apple trees ...

  3. hdu 6206 : Apple 【计算几何 + 分数类】

    题目链接 比赛时C++上__float128都被卡精度,然后扔给队友用Java的BigDecimal过了 算法不多说,求三角形外心可以参考 维基百科 https://zh.wikipedia.org/ ...

  4. HDU 6206 Apple ( 高精度 && 计算几何 && 三点构圆求圆心半径 )

    题意 : 给出四个点,问你第四个点是否在前三个点构成的圆内,若在圆外输出"Accepted",否则输出"Rejected",题目保证前三个点不在一条直线上. 分 ...

  5. HDU 4925 Apple Tree(推理)

    HDU 4925 Apple Tree 题目链接 题意:给一个m*n矩阵种树,每一个位置能够选择种树或者施肥,假设种上去的位置就不能施肥,假设施肥则能让周围果树产量乘2.问最大收益 思路:推理得到肯定 ...

  6. hdu 4925 Apple Tree--2014 Multi-University Training Contest 6

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 Apple Tree Time Limit: 2000/1000 MS (Java/Others ...

  7. HDU 4925 Apple Tree(模拟题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 解题报告:给你n*m的土地,现在对每一块土地有两种操作,最多只能在每块土地上进行两种操作,第一种 ...

  8. HDU 4925 Apple Tree (瞎搞)

    找到规律,各一个种一棵树.或者施肥.先施肥,先种树一样. Apple Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 2621 ...

  9. 2014多校第六场 1005 || HDU 4925 Apple Tree

    题目链接 题意 : 给你一块n×m的矩阵,每一个格子可以施肥或者是种苹果,种一颗苹果可以得到一个苹果,但是如果你在一个格子上施了肥,那么所有与该格子相邻(指上下左右)的有苹果树的地方最后得到的苹果是两 ...

随机推荐

  1. Linux基础学习-crond系统计划任务

    系统计划任务 大部分系统管理工作都是通过定期自动执行某个脚本来完成的,那么如何定期执行某个脚本,从而实现运维的自动化,这就要借助Linux的cron功能了. 计划任务分为一次性计划任务和周期性计划任务 ...

  2. 浅探webpack优化

    由于前端的快速发展,相关工具的发展速度也是相当迅猛,各大框架例如vue,react都有自己优秀的脚手架工具来帮助我们快速启动一个新项目,也正式因为这个原因,我们对于脚手架中最关键的一环webpack相 ...

  3. 【php】【特殊案例】数组调用方法

    As of PHP 5.4.0, you can call any callable stored in a variable. <?php class Foo { static functio ...

  4. 有关Kali更新问题的解决方法。

    近期更新源遭遇诸多不顺,无非是各种依赖问题的报错夹杂着各种稀奇古怪的问题,不过既然是玩Linux,就要做好处理各种疑难杂症的准备.经过了这几天的不断尝试,今天终于解决了更新出错的问题. 本人更新源出现 ...

  5. Java-basic-1

    1. Java Standard Edition (Java SE) Java Enterprise Edition (Java EE): geared toward developing large ...

  6. Statues CodeForces - 129C(bfs)

    In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the oppo ...

  7. poj-1011 sticks(搜索题)

    George took sticks of the same length and cut them randomly until all parts became at most 50 units ...

  8. VR开发的烦恼——范围限制

    本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/52230865 作者:car ...

  9. Python虚拟机之异常控制流(五)

    Python中的异常控制语义结构 在Python虚拟机之异常控制流(四)这一章中,我们考察了Python的异常在虚拟机中的级别上是什么东西,抛出异常这个动作在虚拟机的级别上对应的行为,最后,我们还剖析 ...

  10. luogu3371 【模板】单源最短路径 dijkstra堆优化

    #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> ...