結果

問題 No.622 点と三角柱の内外判定
ユーザー 夕叢霧香(ゆうむらきりか)
提出日時 2017-12-22 00:10:14
言語 Java
(openjdk 23)
結果
AC  
実行時間 57 ms / 1,500 ms
コード長 2,249 bytes
コンパイル時間 2,779 ms
コンパイル使用メモリ 77,624 KB
実行使用メモリ 50,708 KB
最終ジャッジ日時 2024-12-17 22:57:21
合計ジャッジ時間 5,578 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


class Main {
    static double sq(double[]x){
        double sq=0;
        for(int i=0;i<3;++i)sq+=x[i]*x[i];
        return sq;
    }
    static double inn(double[]x,double[]y){
        double sq=0;
        for(int i=0;i<3;++i)sq+=x[i]*y[i];
        return sq;
    }
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        double[]a=new double[3],b=new double[3],c=new double[3],d=new double[3];
;
        for(int i=0;i<3;++i)a[i]=sc.nextDouble();
        for(int i=0;i<3;++i)b[i]=sc.nextDouble()-a[i];
        for(int i=0;i<3;++i)c[i]=sc.nextDouble()-a[i];
        for(int i=0;i<3;++i)d[i]=sc.nextDouble()-a[i];
        double bb=sq(b),bc=inn(b,c),cc=sq(c);
        double det=bb*cc-bc*bc;
        double db=inn(d,b),dc=inn(d,c);
        double x=(cc*db-bc*dc)/det,y=(-bc*db+bb*dc)/det;
        out.println((x>=0&&y>=0&&x+y<=1)?"YES":"NO");
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}
0