結果

問題 No.199 星を描こう
ユーザー kenkooookenkoooo
提出日時 2015-04-29 00:11:18
言語 Java21
(openjdk 21)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,876 bytes
コンパイル時間 2,229 ms
コンパイル使用メモリ 74,656 KB
実行使用メモリ 56,300 KB
最終ジャッジ日時 2023-08-28 18:34:00
合計ジャッジ時間 7,008 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
55,884 KB
testcase_01 AC 115 ms
56,036 KB
testcase_02 AC 114 ms
55,968 KB
testcase_03 AC 115 ms
55,808 KB
testcase_04 AC 115 ms
55,856 KB
testcase_05 AC 115 ms
55,768 KB
testcase_06 AC 115 ms
56,044 KB
testcase_07 AC 117 ms
55,992 KB
testcase_08 AC 116 ms
56,104 KB
testcase_09 AC 114 ms
55,592 KB
testcase_10 AC 117 ms
54,048 KB
testcase_11 AC 116 ms
56,080 KB
testcase_12 AC 117 ms
55,908 KB
testcase_13 AC 116 ms
53,992 KB
testcase_14 AC 116 ms
55,704 KB
testcase_15 WA -
testcase_16 AC 116 ms
55,648 KB
testcase_17 AC 116 ms
56,036 KB
testcase_18 AC 115 ms
55,512 KB
testcase_19 AC 116 ms
55,860 KB
testcase_20 AC 115 ms
56,300 KB
testcase_21 AC 120 ms
55,776 KB
testcase_22 AC 115 ms
55,796 KB
testcase_23 AC 115 ms
55,972 KB
testcase_24 AC 115 ms
55,700 KB
testcase_25 AC 129 ms
55,680 KB
testcase_26 AC 116 ms
56,044 KB
testcase_27 AC 115 ms
55,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] x = new int[5];
		int[] y = new int[5];
		for (int i = 0; i < 5; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}

		int N = x.length;
		ArrayList<Integer> list = new ArrayList<>();
		int start = 0;
		// x座標のもっとも大きい点を始点にする
		for (int i = 1; i < N; i++) {
			if (x[start] < x[i])
				start = i;
		}
		boolean[] used = new boolean[N];
		used[start] = true;
		list.add(start);

		// Y軸の正の向きの単位ベクトル
		double[] prevDir = new double[2];
		prevDir[0] = 0.0;
		prevDir[1] = 1.0;

		while (true) {
			int from = list.get(list.size() - 1);
			double max = -20000000.0;
			int next = -1;

			for (int to = 0; to < N; to++) {
				// 前のベクトルに対して最も内積が大きくなるように次の点を探す
				// そうすると、曲がり角を最大にすることが出来る
				double[] toDir = direction(x, y, from, to);
				double pro = product(prevDir, toDir);
				if (max == pro) {
					System.out.println("NO");
					return;
				}
				if (max < pro) {
					max = pro;
					next = to;
				}
			}

			prevDir = direction(x, y, from, next);
			list.add(next);
			if (used[next]) {
				break;
			}
			used[next] = true;
		}

		if (list.size() == 6) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}

	static double[] direction(int[] X, int[] Y, int from, int to) {
		// fromからtoへの単位ベクトルを返す
		double dx = X[to] - X[from];
		double dy = Y[to] - Y[from];
		return new double[] { dx / Math.sqrt(dx * dx + dy * dy), dy / Math.sqrt(dx * dx + dy * dy) };
	}

	static double product(double[] a, double[] b) {
		// ベクトル内積を返す
		return a[0] * b[0] + a[1] * b[1];
	}

}
0