hdu 6206 Apple 计算几何
来源:互联网 发布:淘宝天猫内部优惠券平台 编辑:程序博客网 时间:2024/06/01 20:11
Apple
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)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 integersx1,y1,x2,y2,x3,y3,x,y , as described above.
The absolute values of integers in input are less than or equal to1,000,000,000,000 .
It is guaranteed that, any three of the four positions do not lie on a straight line.
In the first line of each case, there are eight integers
The absolute values of integers in input are less than or equal to
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
AcceptedRejectedRejected
给出圆上3点坐标,(x,y),判断(x,y)是否在圆外。
高精度分数类,模拟上面公式。
import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;import java.io.PrintWriter;import java.math.BigInteger;import java.util.StringTokenizer; public class Main { public static void main(String[] args) { new Task().solve(); } } class Task { InputReader in = new InputReader(System.in) ; PrintWriter out = new PrintWriter(System.out) ; class F{ BigInteger up ; BigInteger down ; F(BigInteger up , BigInteger down){ this.up = up ; this.down = down ; } F(){ } } F sub(F x , F y){ F s = new F() ; s.down = x.down.multiply(y.down) ; s.up = (x.up.multiply(y.down)).subtract( x.down.multiply(y.up) ) ; BigInteger g = s.down.gcd(s.up) ; s.down = s.down.divide(g) ; s.up = s.up.divide(g) ; return s ; } F add(F x , F y){ F s = new F() ; s.down = x.down.multiply(y.down) ; s.up = (x.up.multiply(y.down)).add( x.down.multiply(y.up) ) ; BigInteger g = s.down.gcd(s.up) ; s.down = s.down.divide(g) ; s.up = s.up.divide(g) ; return s ; } F mult(F x , F y){ F s = new F() ; s.down = x.down.multiply(y.down) ; s.up = x.up.multiply(y.up) ; BigInteger g = s.down.gcd(s.up) ; s.down = s.down.divide(g) ; s.up = s.up.divide(g) ; return s ; } F dist2(F ax , F ay , F bx , F by){ F s = new F() ; F dx = sub(ax , bx) ; dx = mult(dx, dx) ; F dy = sub(ay , by) ; dy = mult(dy, dy) ; s = add(dx , dy) ; return s ; } boolean bigThen(F x , F y){ F x_y = sub(x, y) ; return x_y.up.signum() * x_y.down.signum() > 0 ; } BigInteger x1 , x2 , x3 , y1 , y2 , y3 , x , y ; boolean calc(){ BigInteger A = (x1.multiply(x1)).add(y1.multiply(y1)) ; BigInteger B = (x2.multiply(x2)).add(y2.multiply(y2)) ; BigInteger C = (x3.multiply(x3)).add(y3.multiply(y3)) ; BigInteger G = (y3.subtract(y2)).multiply(x1) ; G = G.add((y1.subtract(y3)).multiply(x2) ) ; G = G.add((y2.subtract(y1)).multiply(x3) ) ; F ox = new F() ; ox.up = (B.subtract(C)).multiply(y1) ; ox.up = ox.up.add((C.subtract(A)).multiply(y2)) ; ox.up = ox.up.add((A.subtract(B)).multiply(y3)) ; ox.down = G.multiply(BigInteger.valueOf(2)) ; F oy = new F() ; oy.up = (C.subtract(B)).multiply(x1) ; oy.up = oy.up.add((A.subtract(C)).multiply(x2)) ; oy.up = oy.up.add((B.subtract(A)).multiply(x3)) ; oy.down = G.multiply(BigInteger.valueOf(2)) ; F r = dist2(ox, oy, new F(x1 , BigInteger.ONE), new F(y1 , BigInteger.ONE)) ; F xy_o = dist2(ox, oy, new F(x , BigInteger.ONE), new F(y , BigInteger.ONE)) ; return bigThen(xy_o, r) ; } void solve(){ int T = in.nextInt() ; while(T-- > 0){ x1 = in.nextBigInteger() ; y1 = in.nextBigInteger() ; x2 = in.nextBigInteger() ; y2 = in.nextBigInteger() ; x3 = in.nextBigInteger() ; y3 = in.nextBigInteger() ; x = in.nextBigInteger() ; y = in.nextBigInteger() ; out.println(calc() ? "Accepted" : "Rejected") ; } out.flush() ; } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = new StringTokenizer(""); } private void eat(String s) { tokenizer = new StringTokenizer(s); } public String nextLine() { try { return reader.readLine(); } catch (Exception e) { return null; } } public boolean hasNext() { while (!tokenizer.hasMoreTokens()) { String s = nextLine(); if (s == null) return false; eat(s); } return true; } public String next() { hasNext(); return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public int[] nextInts(int n) { int[] nums = new int[n]; for (int i = 0; i < n; i++) { nums[i] = nextInt(); } return nums; } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public BigInteger nextBigInteger() { return new BigInteger(next()); } }
阅读全文
0 0
- hdu 6206 Apple 计算几何
- HDU-6206 计算几何+大数
- HDU 6206 Apple (数学 高精度计算)
- hdu6206—Apple(计算几何+高精度)
- hdu 3952 计算几何
- HDU 3694计算几何
- hdu 4195#计算几何
- hdu 4353 计算几何
- hdu 3681 计算几何
- hdu 3629 计算几何
- hdu 3629 计算几何
- hdu 5476 (计算几何)
- hdu 2826 计算几何
- hdu 1007(计算几何)
- hdu 1086 计算几何
- hdu 6158 计算几何
- HDU 3952(计算几何)
- HDU 4033 二分+计算几何
- mysql的安装(mysql-5.7.19-winx64)
- Notepad++或Eclipse删除注释正则表达式
- 2017/09/19第一天使用csdn
- 正则表达式基础
- leetcode 680. Valid Palindrome II
- hdu 6206 Apple 计算几何
- 欢迎使用CSDN-markdown编辑器
- iOS 读取本地JSON文件
- 音频库-bass使用
- UGUI实现模糊查询动态生成列表功能
- Map集合保存数据库
- linux 笔记
- qwb与支教(二分+容斥原理)
- 库