結果
問題 | No.622 点と三角柱の内外判定 |
ユーザー |
|
提出日時 | 2018-01-06 14:57:35 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 145 ms / 1,500 ms |
コード長 | 2,178 bytes |
コンパイル時間 | 3,721 ms |
コンパイル使用メモリ | 78,372 KB |
実行使用メモリ | 41,676 KB |
最終ジャッジ日時 | 2024-12-23 08:34:53 |
合計ジャッジ時間 | 9,915 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
ソースコード
import java.io.*;import java.util.*;public class Main_yukicoder622 {private static Scanner sc;private static Printer pr;private static void solve() {double[] a = new double[3];double[] b = new double[3];double[] c = new double[3];double[] d = new double[3];for (int i = 0; i < 3; i++) {a[i] = sc.nextInt();}for (int i = 0; i < 3; i++) {b[i] = sc.nextInt();}for (int i = 0; i < 3; i++) {c[i] = sc.nextInt();}for (int i = 0; i < 3; i++) {d[i] = sc.nextInt();}double[] ab = v(a, b);double[] ac = v(a, c);double[] no = cross(ab, ac);double tmp = no[0] * (d[0] - a[0]) + no[1] * (d[1] - a[1]) + no[2] * (d[2] - a[2]);double tmp2 = (double)no[0] * no[0] + (double)no[1] * no[1] + (double)no[2] * no[2];double t = -tmp / tmp2;double[] p = {d[0] + t * no[0], d[1] + t * no[1], d[2] + t * no[2]};double[] bc = v(b, c);double[] ca = v(c, a);double[] ap = v(a, p);double[] bp = v(b, p);double[] cp = v(c, p);double[] bccp = cross(bc, cp);double[] abbp = cross(ab, bp);double[] caap = cross(ca, ap);boolean flag = true;if (dot(bccp, abbp) < 0) {flag = false;}if (dot(abbp, caap) < 0) {flag = false;}if (dot(caap, bccp) < 0) {flag = false;}if (flag) {pr.println("YES");} else {pr.println("NO");}// pr.printf("%f %f %f\n", no[0], no[1], no[2]);// pr.printf("%f %f %f\n", p[0], p[1], p[2]);}private static double dot(double[] a, double[] b) {return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];}private static double[] v(double[] a, double[] b) {double[] ret = {b[0] - a[0], b[1] - a[1], b[2] - a[2]};return ret;}private static double[] cross(double[] a, double[] b) {double[] ret = {a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]};return ret;}// ---------------------------------------------------public static void main(String[] args) {sc = new Scanner(System.in);pr = new Printer(System.out);solve();pr.close();sc.close();}private static class Printer extends PrintWriter {Printer(PrintStream out) {super(out);}}}