結果

問題 No.622 点と三角柱の内外判定
ユーザー GrenacheGrenache
提出日時 2018-01-06 14:57:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 135 ms / 1,500 ms
コード長 2,178 bytes
コンパイル時間 3,314 ms
コンパイル使用メモリ 74,272 KB
実行使用メモリ 56,436 KB
最終ジャッジ日時 2023-08-24 22:16:00
合計ジャッジ時間 8,770 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,644 KB
testcase_01 AC 125 ms
55,740 KB
testcase_02 AC 127 ms
55,616 KB
testcase_03 AC 125 ms
55,768 KB
testcase_04 AC 126 ms
55,720 KB
testcase_05 AC 126 ms
55,636 KB
testcase_06 AC 135 ms
55,628 KB
testcase_07 AC 127 ms
55,928 KB
testcase_08 AC 125 ms
55,744 KB
testcase_09 AC 124 ms
56,300 KB
testcase_10 AC 124 ms
55,384 KB
testcase_11 AC 126 ms
55,752 KB
testcase_12 AC 125 ms
55,428 KB
testcase_13 AC 125 ms
55,476 KB
testcase_14 AC 129 ms
55,920 KB
testcase_15 AC 125 ms
55,412 KB
testcase_16 AC 123 ms
55,600 KB
testcase_17 AC 125 ms
55,780 KB
testcase_18 AC 124 ms
55,556 KB
testcase_19 AC 125 ms
55,712 KB
testcase_20 AC 124 ms
55,652 KB
testcase_21 AC 125 ms
55,996 KB
testcase_22 AC 125 ms
55,652 KB
testcase_23 AC 124 ms
56,036 KB
testcase_24 AC 126 ms
56,040 KB
testcase_25 AC 126 ms
53,984 KB
testcase_26 AC 133 ms
55,684 KB
testcase_27 AC 123 ms
56,436 KB
testcase_28 AC 124 ms
55,904 KB
testcase_29 AC 124 ms
56,072 KB
testcase_30 AC 125 ms
55,848 KB
testcase_31 AC 124 ms
55,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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