結果
| 問題 | 
                            No.199 星を描こう
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2016-08-25 16:25:47 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 164 ms / 2,000 ms | 
| コード長 | 1,578 bytes | 
| コンパイル時間 | 4,960 ms | 
| コンパイル使用メモリ | 81,184 KB | 
| 実行使用メモリ | 41,836 KB | 
| 最終ジャッジ日時 | 2024-12-30 03:52:50 | 
| 合計ジャッジ時間 | 9,373 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 25 | 
ソースコード
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);
	}
}