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 ...
随机推荐
- 常用Path路径
正三角形(左):<Path Data="M40,0 L0,30 40,60 z" Stretch="Uniform"/> 正三角形(上):<P ...
- 【IDEA】 Can't Update No tracked branch configured for branch master or the branch doesn't exist. To make your branch track a remote branch call, for example, git branch --set-upstream-to origin/master
IDEA点击GIT更新按钮时,报错如下: Can't UpdateNo tracked branch configured for branch master or the branch doesn' ...
- 【译】DTD - Entities
原文:DTD - Entities 实体用于定义XML文档中特殊字符的快捷方式. 实体主要有四种类型: 内置实体(Built-in entities) 字符实体(Character entities) ...
- CRF++进行中文分词实例
工具包:https://taku910.github.io/crfpp/#tips 语料:http://sighan.cs.uchicago.edu/bakeoff2005/ 安装: 1)下载linu ...
- python基本数据类型list,tuple,set,dict用法以及遍历方法
1.list类型 类似于java的list类型,数据集合,可以追加元素与删除元素. 遍历list可以用下标进行遍历,也可以用迭代器遍历list集合 建立list的时候用[]括号 import sys ...
- s3c6410下移植sqlite3.7.8
http://blog.chinaunix.NET/uid-30441-id-2133838.html 1.下载源代码http://www.sqlite.org/download.html 2.tar ...
- 64_p2
perl-Class-XSAccessor-1.19-10.fc26.x86_64.rpm 12-Feb-2017 15:12 48098 perl-Clipboard-0.13-16.fc26.no ...
- 数据结构与算法之KMP 字符串匹配
举例来说,有一个字符串"DSFFKFJD KFJLKFDLJFJ IWWJKJFJIA",我想知道,里面是否包含另一个字符串"JFJI",有的话就返回在原字符串 ...
- windows下phpstrom中xdebug的使用
https://laravel-china.org/articles/16425/windows-phpstorm-xdebug-breakpoint-debugging
- c++输出保留固定小数位数
cout<<setprecision(6)<<fixed<<ans<<endl;