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. React.js 小书 Lesson20 - 更新阶段的组件生命周期

    作者:胡子大哈 原文链接:http://huziketang.com/books/react/lesson20 转载请注明出处,保留原文链接和作者信息. 从之前的章节我们了解到,组件的挂载指的是将组件 ...

  2. 用jQuery来绑定事件的3种方法和区别

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. java.lang.NumberFormatException: For input string: "1" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:580) at java.lang

    java.lang.NumberFormatException: For input string: "1" at java.lang.NumberFormatException ...

  4. 【6】.net msmq消息队列实例

    1.msmq消息队列windows环境安装 控制面板---->程序和功能---->启用或关闭Windows程序---->Microsoft Message Queue(MSMQ)服务 ...

  5. office2007安装时显示安装程序找不到 office.zh-cn\officeLR.cab怎么办

    根本原因是和VS2008有关解决方法如下:1. 找到vs2008安装程序(光盘,镜像文件,解压文件都一样),找到WCU文件夹在他里面找到WebDesignerCore文件夹,然后打开它找到WebDes ...

  6. <<数学传奇>>概述

    简介 在网易公开课上看完了蔡天新教授的<<数学传奇>>,课程共10集.分别讲述了古希腊的毕达哥拉斯.波斯(伊朗)的 花拉子密和欧玛尔.海亚姆.中国的秦九韶.英国的牛顿.法国的笛 ...

  7. 建一个springboot项目

    1.打开 https://start.spring.io/ 新建一个maven的demo,这里选择的是1.5.18的版本 2.将自动生成的demo导入eclipse,直接选中File里的import, ...

  8. unity3d之相机跟随人物

    一.第三人称视角 _1 先设置好相机与玩家之间的角度 给相机添加代码 using UnityEngine; using System.Collections; namespace CompletePr ...

  9. PAT 1044. Shopping in Mars

    #include <cstdio> #include <cstdlib> #include <vector> #include <climits> #i ...

  10. Iphone各个型号机型的详细参数,尺寸和dpr以及像素

    1.iPhone尺寸规格 2.单位inch(英吋) 1 inch = 2.54cm = 25.4mm 3.iPhone手机宽高 上表中的宽高(width/height)为手机的物理尺寸,包括显示屏和边 ...