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 ...
随机推荐
- JVM学习十二:JVM之性能监控工具
前面我们学习了很多JVM相关的理论知识,那么本节将重点讲述的是工具的使用,正所谓:工欲善其事,必先利其器.因此,本节介绍常用的性能监控工具,用于性能监控和问题排查. 一.系统性能监控 系统性能工具用于 ...
- 【BZOJ】4318: OSU! 期望DP
[题意]有一个长度为n的01序列,每一段极大的连续1的价值是L^3(长度L).现在给定n个实数表示该位为1的概率,求期望总价值.n<=10^5. [算法]期望DP [题解]后缀长度是一个很关键的 ...
- Let's Encrypt 免费通配 https 签名证书 安装方法
安装环境 centOs7 主要通过 acme.sh (bash脚本)来注册签名 git地址:https://github.com/Neilpang/acme.sh 申请证书流程 1.申请证书-> ...
- gitlab使用 —— 多人协同工作(重要技能)
gitlab使用 —— 多人协同工作(重要技能) 学习链接: http://herry2013git.blog.163.com/blog/static/219568011201341111240751 ...
- python3爬虫.2.伪装浏览器
有的网页在爬取时候会报错返回 urllib.error.HTTPError: HTTP Error 403: Forbidden 这是网址在检测连接对象,所以需要伪装浏览器,设置User Agent ...
- nth-child,nth-last-child,only-child,nth-of-type,nth-last-of-type,only-of-type,first-of-type,last-of-type,first-child,last-child伪类区别和用法
我将这坨伪类分成三组,第一组:nth-child,nth-last-child,only-child第二组:nth-of-type,nth-last-of-type,第三组:first-of-tpye ...
- 购物车中的input输入框只能输入数字和输入为0的时候默认为1
<input type="text" value="1" onkeyup="value=(parseInt((value=value.repla ...
- C++之C/C++内存对齐
一.什么是字节对齐,为什么要对齐 现代计算机中内存空间都是按照byte划分的,从理论上讲似乎对任何类型的变量的访问可以从任何地址开始,但实际情况是在访问特定类型变量的时候经常在特 定的内存地址访问,这 ...
- 分布式系统的负载均衡以及ngnix负载均衡的五种策略
一般而言,有以下几种常见的负载均衡策略: 一.轮询. 特点:给每个请求标记一个序号,然后将请求依次派发到服务器节点中,适用于集群中各个节点提供服务能力等同且无状态的场景. 缺点:该策略将节点视为等同, ...
- 使用xbee连接地面站和飞控
Zigbee是一种短距离.低功耗的近距离无线组网通讯技术,主要适用于自动控制和远程控制领域,可以嵌入各种设备. DIGI的ZigBee产品XBee小型但却是一个功能完善的ZigBee收发器(即接收器/ ...