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(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
 
Source
【题意】:给出四个点,问你第四个点是否在前三个点构成的圆内,若在圆外输出"Accepted",否则输出"Rejected",题目保证前三个点不在一条直线上。
【分析】:就是求出三个点外接圆的圆心和半径判断下。精度问题需要用Java大数。已知三点坐标,求外接圆圆心坐标与半径。三点构圆的圆心和半径是能够推导出公式的圆弧方向判断方法和三点确定一个圆的计算方法 高精度问题也只用BigInteger解决即可。
【彩蛋】:

实际上有更简便的方法,直接能用更直接的公式算出圆心 (x0, y0) 和半径的平方 r^2

x0 = ((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)));

y0 = ((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-x0)*(x1-x0)+(y1-y0)*(y1-y0);

里面涉及除法,那就用BigDecimal就能解决了,参考http://blog.csdn.net/cillyb/article/details/78012069

 
import java.math.*;
import java.util.*;
import java.io.*; public class Main{
public static void main(String[] args){
Scanner cin=new Scanner(System.in);
int t=cin.nextInt();
while(t-->)
{
BigDecimal px1, px2, px3, py1, py2, py3, px, py;
px1=cin.nextBigDecimal();
py1=cin.nextBigDecimal();
px2=cin.nextBigDecimal();
py2=cin.nextBigDecimal();
px3=cin.nextBigDecimal();
py3=cin.nextBigDecimal();
px=cin.nextBigDecimal();
py=cin.nextBigDecimal();
BigDecimal a, b, c, d, e, f, px0, py0, r,dis;
a=px1.subtract(px2);
b=py1.subtract(py2);
c=px1.subtract(px3);
d=py1.subtract(py3);
e=px1.multiply(px1).subtract(px2.multiply(px2)).multiply(BigDecimal.valueOf(0.5)).subtract(py2.multiply(py2).subtract(py1.multiply(py1)).multiply(BigDecimal.valueOf(0.5)));
f=px1.multiply(px1).subtract(px3.multiply(px3)).multiply(BigDecimal.valueOf(0.5)).subtract(py3.multiply(py3).subtract(py1.multiply(py1)).multiply(BigDecimal.valueOf(0.5)));
px0=b.multiply(f).subtract(d.multiply(e)).divide(b.multiply(c).subtract(a.multiply(d)),,BigDecimal.ROUND_HALF_UP);
py0=c.multiply(e).subtract(a.multiply(f)).divide(b.multiply(c).subtract(a.multiply(d)),,BigDecimal.ROUND_HALF_UP);
r=px1.subtract(px0).multiply(px1.subtract(px0)).add(py1.subtract(py0).multiply(py1.subtract(py0)));
dis=px.subtract(px0).multiply(px.subtract(px0)).add(py.subtract(py0).multiply(py.subtract(py0)));
if(dis.compareTo(r)==)
System.out.println("Accepted");
else
System.out.println("Rejected"); }
}
}

JAVA高精度

import java.math.BigDecimal;
import java.util.Scanner; public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigDecimal x1, y1, x2, y2, x3, y3, x4, y4;
int _;
_ = sc.nextInt();
while(_-- != )
{
x1 = sc.nextBigDecimal();
y1 = sc.nextBigDecimal();
x2 = sc.nextBigDecimal();
y2 = sc.nextBigDecimal();
x3 = sc.nextBigDecimal();
y3 = sc.nextBigDecimal();
x4 = sc.nextBigDecimal();
y4 = sc.nextBigDecimal();
BigDecimal t;
if(y3.equals(y1))
{
t = y2;
y2 = y3;
y3 = t; t = x2;
x2 = x3;
x3 = t;
}
BigDecimal t1 = (y3.subtract(y1)).multiply(y2.multiply(y2).subtract(y1.multiply(y1)));
BigDecimal t2 = (y3.subtract(y1)).multiply(x2.multiply(x2).subtract(x1.multiply(x1)));
BigDecimal t3 = (y1.subtract(y2)).multiply(y1.multiply(y1).subtract(y3.multiply(y3)));
BigDecimal t4 = (y1.subtract(y2)).multiply(x1.multiply(x1).subtract(x3.multiply(x3)));
BigDecimal t5 = BigDecimal.valueOf().multiply(y1.subtract(y2)).multiply(x3.subtract(x1));
BigDecimal t6 = BigDecimal.valueOf().multiply(y3.subtract(y1)).multiply(x1.subtract(x2));
BigDecimal x0 = (t1.add(t2).subtract(t3).subtract(t4)).divide(t5.subtract(t6)); BigDecimal v1 = y3.multiply(y3);
BigDecimal v2 = y1.multiply(y1);
BigDecimal v3 = BigDecimal.valueOf().multiply(x0).multiply(x3.subtract(x1));
BigDecimal v4 = x1.multiply(x1);
BigDecimal v5 = x3.multiply(x3);
BigDecimal v6 = BigDecimal.valueOf().multiply(y3.subtract(y1));
// System.out.println(v6);
BigDecimal y0 = (v1.subtract(v2).subtract(v3).subtract(v4).add(v5)).divide(v6); BigDecimal z1 = (y0.subtract(y2)).multiply(y0.subtract(y2));
BigDecimal z2 = (x0.subtract(x2)).multiply(x0.subtract(x2));
BigDecimal r = z1.add(z2); BigDecimal tmp1 = (x4.subtract(x0)).multiply(x4.subtract(x0));
BigDecimal tmp2 = (y4.subtract(y0)).multiply(y4.subtract(y0));
BigDecimal dis = tmp1.add(tmp2);
if(dis.compareTo(r) > )
{
System.out.println("Accepted");
}
else
{
System.out.println("Rejected");
} }
}
}

参考emmm

HDU 6206 Apple【计算几何+高精度Java】的更多相关文章

  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 ( 高精度 && 计算几何 && 三点构圆求圆心半径 )

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

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

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

  4. HDU 6206 Apple

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6206 判断给定一点是否在三角形外接圆内. 给定三角形三个顶点的坐标,如何求三角形的外心的坐标呢? 知乎 ...

  5. Apple严控Java太不人性化

    转自:http://www.cdtarena.com/javapx/201307/9115.html Apple为了在系统安全方面得到更好的声誉,对更容易造成系统漏洞的Java进行着严格的控制,并在自 ...

  6. HDU 4998 Rotate (计算几何)

    HDU 4998 Rotate (计算几何) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4998 Description Noting is more ...

  7. hdu 4643 GSM 计算几何 - 点线关系

    /* hdu 4643 GSM 计算几何 - 点线关系 N个城市,任意两个城市之间都有沿他们之间直线的铁路 M个基站 问从城市A到城市B需要切换几次基站 当从基站a切换到基站b时,切换的地点就是ab的 ...

  8. HDU 4925 Apple Tree(推理)

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

  9. hdu 5429 Geometric Progression 高精度浮点数(java版本)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5429 题意:给一段长度不超过100的每个数字(可以是浮点数)的长度不超过1000的序列,问这个序列是否 ...

随机推荐

  1. P1559 运动员最佳匹配问题

    题目描述 羽毛球队有男女运动员各n人.给定2 个n×n矩阵P和Q.P[i][j]是男运动员i和女运动员j配对组成混合双打的男运动员竞赛优势:Q[i][j]是女运动员i和男运动员j配合的女运动员竞赛优势 ...

  2. P1275 魔板

    题目描述 有这样一种魔板:它是一个长方形的面板,被划分成n行m列的n*m个方格.每个方格内有一个小灯泡,灯泡的状态有两种(亮或暗).我们可以通过若干操作使魔板从一个状态改变为另一个状态.操作的方式有两 ...

  3. [USACO Hol10] 臭气弹 图上期望概率dp 高斯

    记住一开始和后来的经过是两个事件因此概率可以大于一 #include<cstdio> #include<iostream> #include<cstdlib> #i ...

  4. share-Nothing原理

    Share nothing理论在数据库设计和优化中的实践应用 首先介绍share nothing概念.最早接触它是在 DataBaseManagentSystem一书的并行数据库章节中. 并行数据库要 ...

  5. [hdu 1398]简单dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1398 看到网上的题解都是说母函数……为什么我觉得就是一个dp就好了,dp[i][j]表示只用前i种硬币 ...

  6. BZOJ1202:狡猾的商人(带权并查集)

    1202: [HNOI2005]狡猾的商人 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1202 Description: 刁姹接到一个 ...

  7. HDU1828 Picture 线段树+扫描线模板题

    Picture Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  8. sysctl -P net.bridge.bridge-nf-call-ip6tables报错解决办法

    问题症状 修改 linux 内核文件 #vi /etc/sysctl.conf后执行sysctl  -P 报错 error: "net.bridge.bridge-nf-call-ip6ta ...

  9. Phantomjs设置浏览器useragent的方式

    Selenium中使用PhantomJS,设置User-Agent的方法. 默认情况下,是没有自动设置User-Agent的:设置PhantomJS的user-agent def __init__(s ...

  10. Install the AWS Command Line Interface on Linux

    Install the AWS Command Line Interface on Linux You can install the AWS Command Line Interface and i ...