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");
}
}
}
}
HDU 6205[计算几何,JAVA]的更多相关文章
- hdu 2108:Shape of HDU(计算几何,判断多边形是否是凸多边形,水题)
Shape of HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU 2202 计算几何
最大三角形 Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- *HDU 2108 计算几何
Shape of HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU 6205 2017沈阳网络赛 思维题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6205 题意:给你n堆牌,原本每一堆的所有牌(a[i]张)默认向下,每次从第一堆开始,将固定个数的牌(b ...
- hdu 3320 计算几何(三维图形几何变换)
openGL Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- *HDU 1007 计算几何
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- *HDU 1392 计算几何
Surround the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- *HDU 1115 计算几何
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- *HDU 1086 计算几何
You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ...
随机推荐
- 使用FormData提交表单及上传文件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...
- LintCode 532: Reverse Pairs
LintCode 35: Reverse Linked List 题目描述 翻转一个链表. 样例 给出一个链表1->2->3->null,这个翻转后的链表为3->2->1 ...
- css各种姿势的水平居中
首先是最常用的,利用margin属性的auto来进行水平居中 margin: 0 auto; 其中0是指上下的margin,auto是左右的margin,margin这个属性的简写是按顺时针走的,也就 ...
- jquery-load()方法
调用load方法的完整格式是:load( url, [data], [callback] ), 其中: •url:是指要导入文件的地址. •data:可选参数:因为Load不仅仅可以导入静态的html ...
- angular 最大字数限制
js可以通过onkeyup onkeydown判断当前节点字数. angular可以通过监听的方式: $scope.input = {//初始化,避免ng-model绑定取不到值 MaxBT:'', ...
- 64_s1
SAASound-3.2-17.fc26.i686.rpm 13-Feb-2017 22:13 27650 SAASound-3.2-17.fc26.x86_64.rpm 13-Feb-2017 23 ...
- Jmeter命令行选项
示例:jmeter.bat -n -j %tmp%\%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%%time:~ ...
- Django 1.10文档中文版Part4
2.10 高级教程:如何编写可重用的apps 2.10.1 重用的概念 The Python Package Index (PyPI)有大量的现成可用的Python库.https://www.djan ...
- JVM内存分配及GC简述
在阐述JVM的内存区域之前,先来看下计算机的存储单位.从小到大依次为Bit,Byte,KB,MB,GB,TB.相邻的单位相差2的10次方. 计算机运行中的存储元件主要分为寄存器(位于CPU)和内存,寄 ...
- 使用非root用户启动tomcat
以下操作均为以root用户运行1.添加tomcat用户组 /usr/sbin/groupadd tomcat 2.添加tomcat用户,并限制登录 /usr/sbin/useradd -s /bin/ ...