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;
} }

最新文章

  1. AsyncTask的初步了解
  2. 最近使用oracle的笔记和少量的正则表达式
  3. Oracle实战训练——ATM取款机业务
  4. iOS开发——UI基础-屏幕适配
  5. cf112a(水题)
  6. 第二百二十天 how can I 坚持
  7. lpad rpad
  8. TaintDroid:智能手机监控实时隐私信息流跟踪系统(三)
  9. android复习-AnsyTask
  10. Quartus14.1中Qsys无法更新custom component的问题
  11. [UWP]附加属性1:概述
  12. 对Vue.js $watch方法的理解
  13. makefile 转载
  14. Python 从入门到实践 试一试 参考代码
  15. CUDA编程之快速入门
  16. 软工实践第五次作业-WordCount进阶需求
  17. getModifiers 方法解释。
  18. JMeter学习(一)工具简单介绍(转载)
  19. 【吉比特】G-bits2018校园春季招聘技术类岗位笔试经验
  20. hdu2609 最小表示法

热门文章

  1. Firebird Fluentdata
  2. MySql数据库与JDBC编程
  3. CSS基础知识---浮动,定位和盒模型
  4. 流畅的python和cookbook学习笔记(二)
  5. hdu 3091 Necklace 状态压缩dp *******
  6. express的proxy实现前后端分离
  7. 使用mpvue搭建一个初始小程序
  8. 52张扑克牌快速生成js
  9. CSS3弹性盒布局
  10. 移动端mate标签设置