結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー uafr_cs
提出日時 2015-06-04 18:49:11
言語 Java
(openjdk 23)
結果
AC  
実行時間 162 ms / 5,000 ms
コード長 2,315 bytes
コンパイル時間 2,434 ms
コンパイル使用メモリ 90,472 KB
実行使用メモリ 55,200 KB
最終ジャッジ日時 2024-11-14 13:50:00
合計ジャッジ時間 6,632 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {
	
	public static final int SIZE = 3;
	
	public static boolean check(final int N, int[] xs, int[] ys){
		final int diff = (xs[0] - xs[1]) * (xs[0] - xs[1]) + (ys[0] - ys[1]) * (ys[0] - ys[1]);
		//System.out.println(Arrays.toString(xs) + " " + Arrays.toString(ys));
		
		for(int i = 1; i < N; i++){
			final int new_diff = (xs[i] - xs[(i + 1) % N]) * (xs[i] - xs[(i + 1) % N]) + (ys[i] - ys[(i + 1) % N]) * (ys[i] - ys[(i + 1) % N]);
			
			//System.out.println(diff + " " + new_diff + " " + xs[i] + " " + ys[i] + " " + xs[i + 1] + " " + ys[i + 1]);
			if(diff != new_diff){
				return false;
			}
		}
		
		return true;
	}
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int[] xs = new int[SIZE];
		int[] ys = new int[SIZE];
		for(int i = 0; i < SIZE; i++){
			final int x = sc.nextInt();
			final int y = sc.nextInt();
			
			xs[i] = x;
			ys[i] = y;
		}
		
		int diff_max = Integer.MIN_VALUE;
		int far_1_point = -1, far_2_point = -1;
		
		for(int i = 0; i < SIZE; i++){
			for(int j = i + 1; j < SIZE; j++){
				final int diff = (xs[i] - xs[j]) * (xs[i] - xs[j]) + (ys[i] - ys[j]) * (ys[i] - ys[j]);
				
				if(diff_max < diff){
					diff_max = diff;
					far_1_point = i;
					far_2_point = j;
				}
			}
		}
		int diff_x = xs[far_2_point] - xs[far_1_point];
		int diff_y = ys[far_2_point] - ys[far_1_point];

		int other_1_point = far_2_point == 1 ? 2 : far_1_point == 0 ? 1 : 0;

		//System.out.println(far_1_point + " " + other_1_point + " " + far_2_point);
		
		if(check(4, 
				new int[]{xs[far_1_point], xs[other_1_point], xs[far_2_point], xs[other_1_point] + diff_y}, 
				new int[]{ys[far_1_point], ys[other_1_point], ys[far_2_point], ys[other_1_point] - diff_x})){
			System.out.println((xs[other_1_point] + diff_y) + " " + (ys[other_1_point] - diff_x));
		}else if(check(4, 
						new int[]{xs[far_1_point], xs[other_1_point], xs[far_2_point], xs[other_1_point] - diff_y}, 
						new int[]{ys[far_1_point], ys[other_1_point], ys[far_2_point], ys[other_1_point] + diff_x})){
			System.out.println((xs[other_1_point] - diff_y) + " " + (ys[other_1_point] + diff_x));
		}else{
			System.out.println(-1);
		}
		
	}
	
}
0