HDU 6206 Apple (高精确度+JAVA BigDecimal)
In the first line of each case, there are eight integers x1,y1,x2,y2,x3,y3,x,y, as described above.
The absolute values of integers in input are less than or equal to 1,000,000,000,000.
It is guaranteed that, any three of the four positions do not lie on a straight line.
-2 0 0 -2 2 0 2 -2
-2 0 0 -2 2 0 0 2
-2 0 0 -2 2 0 1 1
Rejected
Rejected
import java.math.*;
import java.util.*; public class Main {
public static void main(String[] args) { Scanner cin=new Scanner(System.in);// 读入
int T;
T=cin.nextInt();
for(int z=0;z<T;z++){
Point a=new Point();
Point b=new Point();
Point c=new Point();
a.x=cin.nextBigDecimal();
a.y=cin.nextBigDecimal();
b.x=cin.nextBigDecimal();
b.y=cin.nextBigDecimal();
c.x=cin.nextBigDecimal();
c.y=cin.nextBigDecimal();
Point o=waixin(a,b,c);
// BigDecimal r1=dis(o,a); Point d=new Point();
d.x=cin.nextBigDecimal();
d.y=cin.nextBigDecimal(); // if(dis(o, d).compareTo(dis(o,a)) == -1) System.out.println("Rejected");
// else if(dis(o, d).compareTo(dis(o,a)) == -1) System.out.println("Rejected");
// else System.out.println("Accepted");
if(dis(o, d).compareTo(dis(o,a)) == 1) System.out.println("Accepted");
else System.out.println("Rejected"); }
} private static class Point{
public BigDecimal x, y;
public Point(){}
public Point(BigDecimal _x, BigDecimal _y)
{
x = _x; y = _y;
}
} static BigDecimal dis(Point a, Point b)
{
// printf("a.x:%llf b.x%llf a.y:%lf b.y:%lf\n", a.x, b.x, a.y, b.y);
// return (a.x.subtract(b.x))
return (a.x.subtract(b.x)).pow(2).add((a.y.subtract(b.y)).pow(2));
// return (a.x-b.x)*(a.x-b.x);
} static Point waixin(Point a, Point b, Point c)
{
BigDecimal temp =BigDecimal.valueOf(2);
BigDecimal a1 = b.x.subtract(a.x), b1 = b.y.subtract(a.y), c1 = (a1.pow(2).add(b1.pow(2))).divide(temp);
BigDecimal a2 = c.x.subtract(a.x), b2 = c.y.subtract(a.y), c2 = (a2.pow(2).add(b2.pow(2))).divide(temp);
BigDecimal d = (a1.multiply(b2).subtract(a2.multiply(b1)));
Point ret=new Point(a.x.add(c1.multiply(b2).subtract(c2.multiply(b1)).divide(d)),a.y.add(a1.multiply(c2).subtract(a2.multiply(c1)).divide(d)));
// return Point(a.x.add(c1.multiply(b2).subtract(c2.multiply(b1)).divide(d)),a.y.add(a1.multiply(c2).subtract(a2).multiply(c1).divide(d)));
// return Point(a.x + (c1*b2 - c2*b1)/d, a.y + (a1*c2 - a2*c1)/d);
return ret;
} }
HDU 6206 Apple (高精确度+JAVA BigDecimal)的更多相关文章
- HDU 6206 Apple【计算几何+高精度Java】
Problem Description Apple is Taotao's favourite fruit. In his backyard, there are three apple trees ...
- HDU 6206 Apple
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6206 判断给定一点是否在三角形外接圆内. 给定三角形三个顶点的坐标,如何求三角形的外心的坐标呢? 知乎 ...
- hdu 6206 : Apple 【计算几何 + 分数类】
题目链接 比赛时C++上__float128都被卡精度,然后扔给队友用Java的BigDecimal过了 算法不多说,求三角形外心可以参考 维基百科 https://zh.wikipedia.org/ ...
- HDU 6206 Apple ( 高精度 && 计算几何 && 三点构圆求圆心半径 )
题意 : 给出四个点,问你第四个点是否在前三个点构成的圆内,若在圆外输出"Accepted",否则输出"Rejected",题目保证前三个点不在一条直线上. 分 ...
- 编写高质量java代码151个建议
http://blog.csdn.net/aishangyutian12/article/details/52699938 第一章 Java开发中通用的方法和准则 建议1:不要在常量和变量中出现易混 ...
- Java BigDecimal类的使用和注意事项
1.对于金额相关运算,若是精度较高,基本上用BigDecimal进行运算,精度要求低的话用Long.Double即可 2.web后台接受金额用String接受,展示到前端一般也转成 String 3. ...
- [ 高并发]Java高并发编程系列第二篇--线程同步
高并发,听起来高大上的一个词汇,在身处于互联网潮的社会大趋势下,高并发赋予了更多的传奇色彩.首先,我们可以看到很多招聘中,会提到有高并发项目者优先.高并发,意味着,你的前雇主,有很大的业务层面的需求, ...
- 100个高质量Java开发者博客
ImportNew注:原文中还没有100个.作者希望大家一起来推荐高质量的Java开发博客,然后不段补充到这个列表.欢迎你也参与推荐优质的Java开发博客.(声明一下:我们的数学不是体育老师教的!:) ...
- [转] JVM 调优系列 & 高并发Java系列
1.JVM调优总结(1):一些概念:http://www.importnew.com/18694.html 2.JVM调优总结(2):基本垃圾回收算法:http://www.importnew.com ...
随机推荐
- Golang教程:并发介绍
Go是并发语言,而不是并行语言.在讨论Go并发性之前,我们必须首先了解什么是并发,以及并发与并行的区别. 什么是并发 并发(concurrency)是指一次处理大量事情的能力.让我们用一个例子来说明. ...
- [转]真正了解CSS3背景下的@font face规则
本文转自:http://www.zhangxinxu.com/wordpress/2017/03/css3-font-face-src-local/ by zhangxinxu from http:/ ...
- C#根据用户输入字符串,输出大写字母有几个,小写字母有几个
static void Main(string[] args) { // 根据用户输入字符串,输出大写字母有几个,小写字母有几个. Console.WriteLine("请输入一行英文代码& ...
- Eclipse 工具栏无法移动的解决办法
升级到Juno后发现工具栏有些乱 而且无法拖动,试了下http://blog.csdn.net/cxx504659987/article/details/38532599的方法 发现配置文件里没有文中 ...
- [模拟回调] demo1模拟用字符串调用js函数 demo2模拟springmvc controller回调页面js函数
demo1. 模拟用字符串调用js 函数 function dataQuery() { var strFun = "testCallBack"; var strParam = &q ...
- 使用SSH连接LINUX的命令
查看端口号是否被占用 netstat -tunlp|grep 端口号 杀掉 kill-9 pid 后台运行 nohup 应用程序名 & disown -a && exit 屏幕 ...
- HTTP状态码302、303、307区别
HTTP状态码3XX表示重定向,表明浏览器需要执行某些特殊的处理以正确处理请求. 301 Moved Permanently 永久性定向.该状态码表示请求的资源已被分配了新的URI,以后应使用资源现在 ...
- ERROR:Tried to register widget id ==basemapGalleryDiv but that id is already registered解决办法
在ArcGIS Server开发中,遇到DIV已经被注册的情况,不能对原DIV内容进行更新.这里需要调用Dojo的destroyRecursive()方法,逐个销毁该Widget下的子元素及其后代元素 ...
- 【阿里云产品公测】性能测试服务PTS的初步尝试
性能测试服务PTS,对于像我这样对测试毫无概念的新手来说,这服务真的太好了,使用简单,官方教程又明细,连我这样的新手一看都明白了怎样使用. _%GGl$kH 下面是我来简单尝试一下,更多功 ...
- ie6 浏览器的bug
1.IE6不支持连续类的交集选择器 1 #box.box.box1{ 2 width: 200px; 3 height: 200px; 4 ...