hdu6206—Apple(计算几何+高精度)
来源:互联网 发布:什么软件可以写日记 编辑:程序博客网 时间:2024/05/20 01:34
题目链接:传送门
Apple
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 686 Accepted Submission(s): 228
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 integersx1,y1,x2,y2,x3,y3,x,y , as described above.
The absolute values of integers in input are less than or equal to1,000,000,000,000 .
It is guaranteed that, any three of the four positions do not lie on a straight line.
In the first line of each case, there are eight integers
The absolute values of integers in input are less than or equal to
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
AcceptedRejectedRejected
解题思路:高精度求三角形外心
给定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为最终结果。
摘自:链接
import java.util.*;import java.util.zip.CRC32;import java.io.*;import java.math.*;public class Main{public static void main(String[]args){Scanner cin = new Scanner(System.in);int T = cin.nextInt();for( int i = 0 ; i < T ; ++i ){BigDecimal x1,y1,x2,y2,x3,y3,x4,y4;x1 = cin.nextBigDecimal();y1 = cin.nextBigDecimal();x2 = cin.nextBigDecimal();y2 = cin.nextBigDecimal();x3 = cin.nextBigDecimal();y3 = cin.nextBigDecimal();x4 = cin.nextBigDecimal();y4 = cin.nextBigDecimal();BigDecimal A1 = x2.subtract(x1).multiply(BigDecimal.valueOf(2));BigDecimal B1 = y2.subtract(y1).multiply(BigDecimal.valueOf(2));BigDecimal C1 = x2.multiply(x2).add(y2.multiply(y2)).subtract(x1.multiply(x1)).subtract(y1.multiply(y1));BigDecimal A2 = x3.subtract(x2).multiply(BigDecimal.valueOf(2));BigDecimal B2 = y3.subtract(y2).multiply(BigDecimal.valueOf(2));BigDecimal C2 = x3.multiply(x3).add(y3.multiply(y3)).subtract(x2.multiply(x2)).subtract(y2.multiply(y2));BigDecimal x = C1.multiply(B2).subtract(C2.multiply(B1)).divide(A1.multiply(B2).subtract(A2.multiply(B1)));BigDecimal y = A1.multiply(C2).subtract(A2.multiply(C1)).divide(A1.multiply(B2).subtract(A2.multiply(B1)));BigDecimal d1 = x.subtract(x1).multiply(x.subtract(x1)).add(y.subtract(y1).multiply(y.subtract(y1)));BigDecimal d2 = x.subtract(x4).multiply(x.subtract(x4)).add(y.subtract(y4).multiply(y.subtract(y4)));if(d2.compareTo(d1) <= 0) System.out.println("Rejected");else System.out.println("Accepted");}}}
阅读全文
0 0
- hdu6206—Apple(计算几何+高精度)
- HDU6206 几何 + 高精度
- hdu6206 Apple 2017icpc青岛赛区 java高精度类
- HDU 6206 Apple (数学 高精度计算)
- hdu 6206 Apple 计算几何
- noip1998 高精度计算 (高精度)
- Codeforces 1C. Ancient Berland Circus(计算几何:正多边形性质+高精度)
- HDU 6206 Apple(高精度浮点数)
- HDU 6206 Apple(高精度C++)
- 阶乘计算(高精度)
- N!(高精度计算)
- HDU1002(高精度计算)
- 高精度阶层(高精度计算小试牛刀)
- 高精度计算(附高精度加法程序)
- poj2318—TOYS(计算几何+二分)
- POJ2318(计算几何)
- poj1939(计算几何)
- POJ1265Area(计算几何)
- SDUT-3362 数据结构实验之图论六:村村通公路
- 单调栈
- 如何理解设备树中address-cells和size-cells
- 技术分享——mongodb(2)
- 超全数据挖掘面试笔试题(附答案)
- hdu6206—Apple(计算几何+高精度)
- 2018网易秋招--合唱
- 迷宫问题 poj3984
- 遍历Map集合的四种方法
- Java爬虫,信息抓取的实现
- hive2版本安装
- HDOJ 3790-最短路径问题
- websocket准实时推送消息
- 操作系统---进程管理