結果

問題 No.622 点と三角柱の内外判定
ユーザー GrenacheGrenache
提出日時 2018-01-06 14:57:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 1,500 ms
コード長 2,178 bytes
コンパイル時間 3,275 ms
コンパイル使用メモリ 78,036 KB
実行使用メモリ 41,624 KB
最終ジャッジ日時 2024-06-02 11:27:12
合計ジャッジ時間 8,388 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
40,120 KB
testcase_01 AC 118 ms
41,316 KB
testcase_02 AC 124 ms
41,236 KB
testcase_03 AC 121 ms
41,352 KB
testcase_04 AC 116 ms
40,996 KB
testcase_05 AC 118 ms
41,236 KB
testcase_06 AC 125 ms
41,304 KB
testcase_07 AC 126 ms
41,556 KB
testcase_08 AC 117 ms
41,136 KB
testcase_09 AC 122 ms
41,108 KB
testcase_10 AC 123 ms
41,344 KB
testcase_11 AC 124 ms
41,088 KB
testcase_12 AC 123 ms
41,312 KB
testcase_13 AC 123 ms
40,248 KB
testcase_14 AC 109 ms
40,180 KB
testcase_15 AC 124 ms
41,276 KB
testcase_16 AC 120 ms
40,128 KB
testcase_17 AC 124 ms
41,472 KB
testcase_18 AC 110 ms
40,484 KB
testcase_19 AC 123 ms
41,320 KB
testcase_20 AC 109 ms
40,012 KB
testcase_21 AC 122 ms
41,356 KB
testcase_22 AC 123 ms
41,312 KB
testcase_23 AC 124 ms
40,404 KB
testcase_24 AC 123 ms
41,580 KB
testcase_25 AC 123 ms
41,232 KB
testcase_26 AC 112 ms
40,308 KB
testcase_27 AC 122 ms
41,604 KB
testcase_28 AC 124 ms
41,444 KB
testcase_29 AC 120 ms
41,420 KB
testcase_30 AC 121 ms
41,384 KB
testcase_31 AC 127 ms
41,624 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