Problem Description
Apple is Taotao's favourite fruit. In his backyard, there are three apple trees with coordinates (x1,y1), (x2,y2), and (x3,y3). Now Taotao is planning to plant a new one, but he is not willing to take these trees too close. He believes that the new apple tree should be outside the circle which the three apple trees that already exist is on. Taotao picked a potential position (x,y) of the new tree. Could you tell him if it is outside the circle or not?
 
Input
The first line contains an integer T, indicating that there are T(T≤30) cases.
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.
 
Output
For each case, output "Accepted" if the position is outside the circle, or "Rejected" if the position is on or inside the circle.
 
Sample Input
3
-2 0 0 -2 2 0 2 -2
-2 0 0 -2 2 0 0 2
-2 0 0 -2 2 0 1 1
 
Sample Output
Accepted
Rejected
Rejected
 
题目大意:
  给三个不在同一条直线上的点的坐标,判断第四个点在不在这三个点确定的圆的圆内,如果在,就输出Rejected,不然输出Accepted。
 
思路:
  一开始是用C++,疯狂调ESP的参数,但是wa了10多法发现是在是不好做,又看到大家都在用JAVA,所以就想到了JAVA里的BigDecimal类可以进行大数据高精确度处理。因为是第一次在OJ上提交JAVA,开始虽然写对了,但是也老是wa。后来发现在HDU中,主类名的Main要求M必须大写,开始叫了好几发main于是老是错而不是报CE。。。所以就记录下来,以备以后使用
 
AC代码:
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)的更多相关文章

  1. HDU 6206 Apple【计算几何+高精度Java】

    Problem Description Apple is Taotao's favourite fruit. In his backyard, there are three apple trees ...

  2. HDU 6206 Apple

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6206 判断给定一点是否在三角形外接圆内. 给定三角形三个顶点的坐标,如何求三角形的外心的坐标呢? 知乎 ...

  3. hdu 6206 : Apple 【计算几何 + 分数类】

    题目链接 比赛时C++上__float128都被卡精度,然后扔给队友用Java的BigDecimal过了 算法不多说,求三角形外心可以参考 维基百科 https://zh.wikipedia.org/ ...

  4. HDU 6206 Apple ( 高精度 && 计算几何 && 三点构圆求圆心半径 )

    题意 : 给出四个点,问你第四个点是否在前三个点构成的圆内,若在圆外输出"Accepted",否则输出"Rejected",题目保证前三个点不在一条直线上. 分 ...

  5. 编写高质量java代码151个建议

    http://blog.csdn.net/aishangyutian12/article/details/52699938 第一章  Java开发中通用的方法和准则 建议1:不要在常量和变量中出现易混 ...

  6. Java BigDecimal类的使用和注意事项

    1.对于金额相关运算,若是精度较高,基本上用BigDecimal进行运算,精度要求低的话用Long.Double即可 2.web后台接受金额用String接受,展示到前端一般也转成 String 3. ...

  7. [ 高并发]Java高并发编程系列第二篇--线程同步

    高并发,听起来高大上的一个词汇,在身处于互联网潮的社会大趋势下,高并发赋予了更多的传奇色彩.首先,我们可以看到很多招聘中,会提到有高并发项目者优先.高并发,意味着,你的前雇主,有很大的业务层面的需求, ...

  8. 100个高质量Java开发者博客

    ImportNew注:原文中还没有100个.作者希望大家一起来推荐高质量的Java开发博客,然后不段补充到这个列表.欢迎你也参与推荐优质的Java开发博客.(声明一下:我们的数学不是体育老师教的!:) ...

  9. [转] JVM 调优系列 & 高并发Java系列

    1.JVM调优总结(1):一些概念:http://www.importnew.com/18694.html 2.JVM调优总结(2):基本垃圾回收算法:http://www.importnew.com ...

随机推荐

  1. <数据挖掘导论>读书笔记6关联分析的高级概念

    处理联系属性: 基于离散化的方法 基于统计学的方法 非离散化方法 处理概念分层 定义在一个特定领域的各种实体或者概念的多层组织.概念分层可以用有向无环图DAG来标示. 序列模式 可选计数方案 COBJ ...

  2. CentOS 7禁止IPv6

    如何在CentOS 7中禁止IPv6 https://Linux.cn/article-4935-1.html 最近,我的一位朋友问我该如何禁止IPv6.在搜索了一番之后,我找到了下面的方案.下面就是 ...

  3. js 获取 客户区 大小

    js 获取 客户区 大小 本文内容来自<javascript高级程序设计(第二版)> 内容, 只是方便大家以后可能会用到... <script type="text/jav ...

  4. javascript typeof 和 instanceof 的区别和联系

      这篇文章是我看完<JavaScript高级程序设计(第2版)>书籍的随笔文章,目的只有一个,以备自己和网友们方便参考和记忆! typeof是什么?       typeof 是一个操作 ...

  5. WCF 服务管理

    public class ContractManager { IDictionary stateSaver = new Hashtable(); /// <summary> /// 安装服 ...

  6. JavaScript call 和apply 的理解

    这两个方法对于一些新手而言难耐弄清他们到底是怎么回事,对我我来讲我对call和apply的方法理解的也比较含糊.今天闲来无事准备彻底搞call和apply到底是怎么回事.本着互联网分享精神.我将我自己 ...

  7. window.open()被浏览器拦截问题汇总

    一.问题描述 最近在做项目的时候碰到了使用window.open被浏览器拦截的情况,虽然在自己的环境可以对页面进行放行,但是对用户来说,不能要求用户都来通过拦截.何况当出现拦截时,很多用户根本不知道发 ...

  8. SEO学习

    一.什么是SEO SEO是由英文Search Engine Optimization缩写而来, 中文意译为“搜索引擎优化”!SEO是指通过对网站进行站内优化(网站结构调整.网站内容建设.网站代码优化等 ...

  9. Tomcat源码(二):tomcat启动之前的初始化

    当tomcat启动的时候 首先会加载 org.apache.ctalina.startup.BootStrap类. 使用eclipse或idea启动tomcat其实就是在启动这个类的main方法 根据 ...

  10. easypoi导出单个sheet和多个sheet

    今天有时间研究了一下easypoi,感觉使用了easypoi导出excel方便了很多,不用写很多复杂的反射,只需要使用注解和一些工具类就可以实现常用的excel的导出,接下来介绍一下easypoi如何 ...