poj 6206 Apple

Apple

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 806    Accepted Submission(s): 267

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

 

只需要输入三个点的坐标即可
p1(x1,y1)  p2(x2,y2)   p3(x3,y3)
A=x1*x1+y1*y1
B=x2*x2+y2*y2
C=x3*x3+y3*y3
G=(y3-y2)*x1+(y1-y3)*x2+(y2-y1)*x3
X=((B-C)*y1+(C-A)*y2+(A-B)*y3)/(2*G)
Y=((C-B)*x1+(A-C)*x2+(B-A)*x3)/(2*G)

  

import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner cin=new Scanner(System.in);
        BigDecimal A,B,C,G;
        BigDecimal x1,x2,x3,y1,y2,y3,x0,y0;
        BigDecimal X,Y;
        int t;
        t=cin.nextInt();
        while(t-->0)
        {
            x1=cin.nextBigDecimal();
            y1=cin.nextBigDecimal();
            x2=cin.nextBigDecimal();
            y2=cin.nextBigDecimal();
            x3=cin.nextBigDecimal();
            y3=cin.nextBigDecimal();
            x0=cin.nextBigDecimal();
            y0=cin.nextBigDecimal();
            A=x1.multiply(x1).add(y1.multiply(y1));
            B=x2.multiply(x2).add(y2.multiply(y2));
            C=x3.multiply(x3).add(y3.multiply(y3));
            G=BigDecimal.valueOf(1);
            G=y3.subtract(y2).multiply(x1).add(y1.subtract(y3).multiply(x2)).add(y2.subtract(y1).multiply(x3));
            X=B.subtract(C).multiply(y1).add(C.subtract(A).multiply(y2)).add(A.subtract(B).multiply(y3)).divide(BigDecimal.valueOf(2));
            Y=C.subtract(B).multiply(x1).add(A.subtract(C).multiply(x2)).add(B.subtract(A).multiply(x3)).divide(BigDecimal.valueOf(2));
            x0=x0.multiply(G);
            y0=y0.multiply(G);
            x1=x1.multiply(G);
            y1=y1.multiply(G);
            BigDecimal a=x0.subtract(X).multiply(x0.subtract(X)).add( y0.subtract(Y).multiply(y0.subtract(Y)));
            BigDecimal b=x1.subtract(X).multiply(x1.subtract(X)).add( y1.subtract(Y).multiply(y1.subtract(Y)));
            if(a.compareTo(b)>0)
                System.out.println("Accepted");
            else
                System.out.println("Rejected");
        }
    }
}

  

时间: 2024-08-27 02:33:07

poj 6206 Apple的相关文章

poj 3321 Apple Trie

/* poj 3321 Apple Trie 这道题的关键是如何将一个树建成一个一维数组利用树状数组来解题! 可以利用dfs()来搞定,我们在对一个节点深搜后,所经过的节点的数目就是该节点的子树的数目 所以我们利用start[i]数组来记录 i 节点在一维数组的起始位置, 而end[i]则是记录i节点所有孩子 节点最后一个孩子节点在数组的位置,那么end[i]-start[i]+1,就是 i 节点(包括自身)和其所有孩子节点的 数目.数组建好了,那么最后就是套用树状数组模板进行求解了! */ #

poj 3321:Apple Tree(树状数组,提高题)

Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18623   Accepted: 5629 Description There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been

POJ - 3321 Apple Tree (线段树 + 建树 + 思维转换)

POJ - 3321 Apple Tree Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status Description There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very muc

【树状数组】POJ 3321 Apple Tree

/** * @author johnsondu * @time 2015.8.25 20:04 * @problem POJ 3321 Apple Tree * @type Binary Index Tree * @description 从根节点开始,dfs遍历树,先访问的节点 * 记为beg, 从当前结点遍历访问到的最后的 * 一个节点,记为end.然后按照树状数组的 * 方法进行求解. * @url http://poj.org/problem?id=3321 */ #include <i

POJ 3321 Apple Tree (dfs+线段树)

题目大意: 修改树上的节点,然后求子树的和. 思路分析: dfs 重新编号,烂大街了... #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #define maxn 100005 #define lson num<<1,s,mid #define rson num<<1|1,mid+1,e using namespace std

POJ 2468 Apple Tree 树上瞎搞分组背包

昨晚Debug了好久始终找不出哪里错了,今早再一看发现自己已荣升逗比Beta 2.0 Version. 个人感觉此题为HDU 4003 的弱化版. 把每棵子树都看成一类商品,在每类商品中至多选一件.则问题转化为最基本的分组背包问题. dp[s][c][k] c == 1时,表示在s结点不返回时走K的最大收益,c == 0时,表示在s结点重新返回时走k步的最大收益. 可以dfs从底到顶更新dp.值得一提的是,要保证每个结点的dp[s][c][k]只会被dfs一次,即不能重复更新. 因为重复的dfs

POJ 2385 Apple Catching 接苹果 DP

题目链接:POJ 2385 Apple Catching Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7858   Accepted: 3846 Description It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently number

POJ 3321 Apple Tree (树状数组)

Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 21191   Accepted: 6436 Description There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been

#5 DIV2 A POJ 3321 Apple Tree 摘苹果 构建线段树

Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25232   Accepted: 7503 Description There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been