結果

問題 No.199 星を描こう
ユーザー 37zigen37zigen
提出日時 2016-08-25 16:25:47
言語 Java19
(openjdk 21)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 1,578 bytes
コンパイル時間 5,024 ms
コンパイル使用メモリ 81,060 KB
実行使用メモリ 56,760 KB
最終ジャッジ日時 2023-08-28 18:47:50
合計ジャッジ時間 8,869 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
56,404 KB
testcase_01 AC 142 ms
56,244 KB
testcase_02 AC 134 ms
56,008 KB
testcase_03 AC 131 ms
56,484 KB
testcase_04 AC 131 ms
56,368 KB
testcase_05 AC 133 ms
55,848 KB
testcase_06 AC 132 ms
56,160 KB
testcase_07 AC 131 ms
56,368 KB
testcase_08 AC 131 ms
56,356 KB
testcase_09 AC 131 ms
56,424 KB
testcase_10 AC 132 ms
56,324 KB
testcase_11 AC 129 ms
54,504 KB
testcase_12 AC 131 ms
53,796 KB
testcase_13 AC 130 ms
56,076 KB
testcase_14 AC 133 ms
56,760 KB
testcase_15 AC 133 ms
56,108 KB
testcase_16 AC 133 ms
56,040 KB
testcase_17 AC 133 ms
56,520 KB
testcase_18 AC 134 ms
56,156 KB
testcase_19 AC 131 ms
56,060 KB
testcase_20 AC 133 ms
56,016 KB
testcase_21 AC 134 ms
56,068 KB
testcase_22 AC 141 ms
56,388 KB
testcase_23 AC 140 ms
56,228 KB
testcase_24 AC 139 ms
56,224 KB
testcase_25 AC 140 ms
56,108 KB
testcase_26 AC 140 ms
56,056 KB
testcase_27 AC 140 ms
55,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package No100番台;

import java.awt.geom.Line2D;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

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

	void solver() {
		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");
		}
	}
	public static 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>(){
			public int compare(Integer a, Integer b){
				if(x[a] != x[b])return x[a] < x[b] ? -1 : 1;
				if(y[a] != y[b])return y[a] < y[b] ? -1 : 1;
				return 0;
			}
		});
		
		int[] ret = new int[n + 1];
		int p = 0;
		for(int i = 0;i < n;i++){
			if(p >= 1 && x[ret[p-1]] == x[ord[i]] && y[ret[p-1]] == y[ord[i]])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[ord[i]] && y[ret[p-1]] == y[ord[i]])continue;
			while(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