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 ...
随机推荐
- 分享一个彻底冻结对象的函数——来自阮一峰老师的《ECMAScript 6 入门》
var constantize = (obj) => { Object.freeze(obj); Object.keys(obj).forEach( (key, i) => { if ( ...
- 数组与集合List的相互转化
数组转化为集合 #此运用的是Arrays中的asList方法,返回一个List集合 *当数组元素为基本数据类型是把整个数组当作一个元素放入List集合中,代码举例: ,,}; List<int[ ...
- 【CodeForces】914 H. Ember and Storm's Tree Game 动态规划+排列组合
[题目]H. Ember and Storm's Tree Game [题意]Zsnuoの博客 [算法]动态规划+排列组合 [题解]题目本身其实并不难,但是大量干扰因素让题目显得很神秘. 参考:Zsn ...
- Oracle数据库语句
Oracle数据库语句 ORACLE支持五种类型的完整性约束 NOT NULL (非空)--防止NULL值进入指定的列,在单列基础上定义,默认情况下,ORACLE允许在任何列中有NULL值. CHEC ...
- wepy 使用组件时一个注意事项。。。
组件传值prop 必须使用指定引用地址的数据 如果像下面这样 取为空shop 中的phone ,后续获取数据或就算 shop中有phone元素 子组件也无法获取到修改后的值 <template& ...
- 【洛谷P2014】选课
题目描述 在大学里每个学生,为了达到一定的学分,必须从很多课程里选择一些课程来学习,在课程里有些课程必须在某些课程之前学习,如高等数学总是在其它课程之前学习.现在有N门功课,每门课有个学分,每门课有一 ...
- 【leetcode 简单】第一题 两数之和
给定一个整数数组和一个目标值,找出数组中和为目标值的两个数. 你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 示例: 给定 nums = [2, 7, 11, 15], target ...
- 移动端meta声明
<!DOCTYPE html> <!-- 使用 HTML5 doctype,不区分大小写 --><html lang="zh-cmn-Hans"> ...
- P2622 关灯问题II (状态压缩入门)
题目链接: https://www.luogu.org/problemnew/show/P2622 具体思路:暴力,尝试每个开关,然后看所有的情况中存不存在灯全部关闭的情况,在储存所有灯的情况的时候, ...
- 【shell】shell编程总结
总结一下在写shell脚本时的常见注意事项: 1.shell脚本中的命令最好用命令的全路径,如果不知道全路径可以用which cmd查找命令的全路径. 2.shell脚本中定义环境变量用export ...