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

 
  1. import java.math.*;
  2. import java.util.*;
  3. import java.io.*;
  4.  
  5. public class Main{
  6. public static void main(String[] args){
  7. Scanner cin=new Scanner(System.in);
  8. int t=cin.nextInt();
  9. while(t-->)
  10. {
  11. BigDecimal px1, px2, px3, py1, py2, py3, px, py;
  12. px1=cin.nextBigDecimal();
  13. py1=cin.nextBigDecimal();
  14. px2=cin.nextBigDecimal();
  15. py2=cin.nextBigDecimal();
  16. px3=cin.nextBigDecimal();
  17. py3=cin.nextBigDecimal();
  18. px=cin.nextBigDecimal();
  19. py=cin.nextBigDecimal();
  20. BigDecimal a, b, c, d, e, f, px0, py0, r,dis;
  21. a=px1.subtract(px2);
  22. b=py1.subtract(py2);
  23. c=px1.subtract(px3);
  24. d=py1.subtract(py3);
  25. 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)));
  26. 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)));
  27. px0=b.multiply(f).subtract(d.multiply(e)).divide(b.multiply(c).subtract(a.multiply(d)),,BigDecimal.ROUND_HALF_UP);
  28. py0=c.multiply(e).subtract(a.multiply(f)).divide(b.multiply(c).subtract(a.multiply(d)),,BigDecimal.ROUND_HALF_UP);
  29. r=px1.subtract(px0).multiply(px1.subtract(px0)).add(py1.subtract(py0).multiply(py1.subtract(py0)));
  30. dis=px.subtract(px0).multiply(px.subtract(px0)).add(py.subtract(py0).multiply(py.subtract(py0)));
  31. if(dis.compareTo(r)==)
  32. System.out.println("Accepted");
  33. else
  34. System.out.println("Rejected");
  35.  
  36. }
  37. }
  38. }

JAVA高精度

  1. import java.math.BigDecimal;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5. public static void main(String[] args) {
  6. Scanner sc = new Scanner(System.in);
  7. BigDecimal x1, y1, x2, y2, x3, y3, x4, y4;
  8. int _;
  9. _ = sc.nextInt();
  10. while(_-- != )
  11. {
  12. x1 = sc.nextBigDecimal();
  13. y1 = sc.nextBigDecimal();
  14. x2 = sc.nextBigDecimal();
  15. y2 = sc.nextBigDecimal();
  16. x3 = sc.nextBigDecimal();
  17. y3 = sc.nextBigDecimal();
  18. x4 = sc.nextBigDecimal();
  19. y4 = sc.nextBigDecimal();
  20. BigDecimal t;
  21. if(y3.equals(y1))
  22. {
  23. t = y2;
  24. y2 = y3;
  25. y3 = t;
  26.  
  27. t = x2;
  28. x2 = x3;
  29. x3 = t;
  30. }
  31. BigDecimal t1 = (y3.subtract(y1)).multiply(y2.multiply(y2).subtract(y1.multiply(y1)));
  32. BigDecimal t2 = (y3.subtract(y1)).multiply(x2.multiply(x2).subtract(x1.multiply(x1)));
  33. BigDecimal t3 = (y1.subtract(y2)).multiply(y1.multiply(y1).subtract(y3.multiply(y3)));
  34. BigDecimal t4 = (y1.subtract(y2)).multiply(x1.multiply(x1).subtract(x3.multiply(x3)));
  35. BigDecimal t5 = BigDecimal.valueOf().multiply(y1.subtract(y2)).multiply(x3.subtract(x1));
  36. BigDecimal t6 = BigDecimal.valueOf().multiply(y3.subtract(y1)).multiply(x1.subtract(x2));
  37. BigDecimal x0 = (t1.add(t2).subtract(t3).subtract(t4)).divide(t5.subtract(t6));
  38.  
  39. BigDecimal v1 = y3.multiply(y3);
  40. BigDecimal v2 = y1.multiply(y1);
  41. BigDecimal v3 = BigDecimal.valueOf().multiply(x0).multiply(x3.subtract(x1));
  42. BigDecimal v4 = x1.multiply(x1);
  43. BigDecimal v5 = x3.multiply(x3);
  44. BigDecimal v6 = BigDecimal.valueOf().multiply(y3.subtract(y1));
  45. // System.out.println(v6);
  46. BigDecimal y0 = (v1.subtract(v2).subtract(v3).subtract(v4).add(v5)).divide(v6);
  47.  
  48. BigDecimal z1 = (y0.subtract(y2)).multiply(y0.subtract(y2));
  49. BigDecimal z2 = (x0.subtract(x2)).multiply(x0.subtract(x2));
  50. BigDecimal r = z1.add(z2);
  51.  
  52. BigDecimal tmp1 = (x4.subtract(x0)).multiply(x4.subtract(x0));
  53. BigDecimal tmp2 = (y4.subtract(y0)).multiply(y4.subtract(y0));
  54. BigDecimal dis = tmp1.add(tmp2);
  55. if(dis.compareTo(r) > )
  56. {
  57. System.out.println("Accepted");
  58. }
  59. else
  60. {
  61. System.out.println("Rejected");
  62. }
  63.  
  64. }
  65. }
  66. }

参考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. Java语言常用的运算符和表达式详解

    Java提供了丰富的运算符,如算术运算符.关系运算符.逻辑运算符.位运算符等等.Java的表达式就是用运算符连接起来的符合Java规则的式子.运算符的优先级决定了表达式中运算执行的先后顺序.在编写程序 ...

  2. hihocoder 1320 压缩字符串(字符串+dp)

    题解: 其实就是对应三种dp的转移方式 1.拼接类型 dp[i][j] = dp[i][c] + dp[c][j] 2.不变类型 dp[i][j] = j-i+1 3.重复类型(必须满足有k个循环节) ...

  3. 【题解】ZJOI2007报表统计

    洛谷传送门 主要思路大概也是差不多的,对于两种询问分别用线段树与平衡树来维护. 1.MIN_SORT_GAP:显然平衡树简单操作,来一发前驱.后继即可. 2.MIN_GAP:这一个我用的是线段树:可以 ...

  4. Linux相关——关于文件调用

    本文主要记录几个常见文件调用(表示为了造数据试了n种方法,,,发现了一些神奇的东西,会在下面一一说明. 首先在程序中我们可以打开和关闭程序. 常见的freopen用法简单,但是只能使用一次,如果在程序 ...

  5. 【NOIP2017 D1 T1 小凯的疑惑】

    题目描述 小凯手中有两种面值的金币,两种面值均为正整数且彼此互素.每种金币小凯都有 无数个.在不找零的情况下,仅凭这两种金币,有些物品他是无法准确支付的.现在小 凯想知道在无法准确支付的物品中,最贵的 ...

  6. Codeforces Round #532 (Div. 2) 题解

    Codeforces Round #532 (Div. 2) 题目总链接:https://codeforces.com/contest/1100 A. Roman and Browser 题意: 给出 ...

  7. TCP ------ RST的产生

    产生RST的几个原因 1.请求超时 有89.27两台主机.主机89向主机27发送了一个SYN,表示希望连接8888端口,主机27回应了主机89一个SYN表示可以连接.但是主机89莫名其妙的发送了一个R ...

  8. 大数问题,通常用JAVA

    e.g. HDU1002 简单加法 import java.math.BigInteger; import java.util.Scanner; public class Main { public ...

  9. 计算机网络中七层,五层,四层协议;IP 地址子网划分

    七层协议: 7 应用层(http) 6 表示层(上层用户可以相互识别的数据:jpg) 5 会话层(不同主机不同线程间的通信) 4 运输层(tcp/ip:传输层提供端到端的透明数据服务)/差错控制和流量 ...

  10. NYOJ 170 网络的可靠性 (数学)

    题目链接 描述 A公司是全球依靠的互联网解决方案提供商,也是2010年世博会的高级赞助商.它将提供先进的网络协作技术,展示其"智能+互联"的生活概念,同时为参观者提供高品质的个人体 ...