結果

問題 No.199 星を描こう
ユーザー 37zigen37zigen
提出日時 2016-10-26 13:05:30
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,030 bytes
コンパイル時間 4,126 ms
コンパイル使用メモリ 82,908 KB
実行使用メモリ 54,772 KB
最終ジャッジ日時 2024-05-03 06:08:12
合計ジャッジ時間 9,424 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
41,756 KB
testcase_01 AC 150 ms
41,376 KB
testcase_02 AC 145 ms
41,560 KB
testcase_03 AC 145 ms
41,856 KB
testcase_04 AC 149 ms
41,736 KB
testcase_05 AC 149 ms
41,624 KB
testcase_06 AC 148 ms
41,608 KB
testcase_07 AC 149 ms
41,532 KB
testcase_08 AC 153 ms
41,560 KB
testcase_09 AC 150 ms
41,528 KB
testcase_10 AC 154 ms
42,024 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 149 ms
41,772 KB
testcase_14 WA -
testcase_15 AC 144 ms
41,520 KB
testcase_16 AC 152 ms
41,844 KB
testcase_17 AC 152 ms
41,708 KB
testcase_18 AC 146 ms
41,844 KB
testcase_19 AC 150 ms
41,872 KB
testcase_20 WA -
testcase_21 AC 145 ms
41,600 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 150 ms
41,576 KB
testcase_25 AC 150 ms
41,576 KB
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package contest678;

import java.awt.geom.Line2D;
import java.util.*;

public class F {
	public static void main(String[] args) {
		new F().run();
	}

	void run() {
		solver();
	}

	void solver() {
		// Scanner sc = new Scanner(System.in);

		// int n = sc.nextInt();
		// int[][] qs = new int[n][];
		// for (int Q = 0; Q < n; ++Q) {
		// int t = sc.nextInt();// 0:add,1:removek,2:calc
		// if (t == 1) {
		// qs[Q] = new int[] { t, sc.nextInt(), sc.nextInt(), Q };
		// } else if (t == 2) {
		// qs[Q] = new int[] { t, sc.nextInt() - 1 };
		// } else if (t == 3) {
		// qs[Q] = new int[] { t, sc.nextInt() };
		// }
		// }
		Scanner sc = new Scanner(System.in);
		double[] x = new double[5];
		double[] y = new double[5];
		for (int i = 0; i < 5; i++) {
			x[i] = sc.nextDouble();
			y[i] = sc.nextDouble();
		}
		int[] d = convexHull(x, y);
		if (d.length == 5) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

	int[] convexHull(final double[] x, final double[] y) {
		int n = x.length;
		Integer[] ord = new Integer[n];
		for (int i = 0; i < n; ++i) {
			ord[i] = i;
		}
		Arrays.sort(ord, new Comparator<Integer>() {
			@Override
			public int compare(Integer o1, Integer o2) {
				if (x[o1] != x[o2]) {
					return Double.compare(x[o1], x[o2]);
				} else {
					return Double.compare(y[o1], y[o2]);
				}
			}
		});

		int[] ret = new int[n + 1];
		int p = 0;
		for (int i = 0; i < n; ++i) {
			if (p >= 1 && x[ord[i]] == x[ret[p - 1]] && y[ord[i]] == y[ret[p - 1]])
				continue;
			while (p >= 2 && Line2D.relativeCCW(x[ret[p - 2]], y[ret[p - 2]], x[ret[p - 1]], y[ret[p - 1]], x[ord[i]],
					y[ord[i]]) == 1)
				p--;
			ret[p++] = ord[i];
		}

		int inf = p + 1;
		for (int i = n - 2; i >= 0; --i) {
			if (x[ret[p - 1]] == x[ret[i]] && y[ret[p - 1]] == y[ret[i]])
				continue;
			if (p >= inf && Line2D.relativeCCW(x[ret[p - 2]], y[ret[p - 2]], x[ret[p - 1]], y[ret[p - 1]], x[ord[i]],
					y[ord[i]]) == 1)
				p--;
			ret[p++] = ord[i];
		}

		return Arrays.copyOf(ret, p - 1);
	}
}
0