結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー tsunabittsunabit
提出日時 2019-12-18 16:30:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 164 ms / 5,000 ms
コード長 1,657 bytes
コンパイル時間 3,392 ms
コンパイル使用メモリ 76,112 KB
実行使用メモリ 57,004 KB
最終ジャッジ日時 2023-09-20 19:04:06
合計ジャッジ時間 8,238 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 152 ms
56,720 KB
testcase_01 AC 121 ms
55,676 KB
testcase_02 AC 151 ms
56,984 KB
testcase_03 AC 149 ms
56,748 KB
testcase_04 AC 121 ms
55,644 KB
testcase_05 AC 121 ms
55,556 KB
testcase_06 AC 127 ms
55,656 KB
testcase_07 AC 125 ms
55,744 KB
testcase_08 AC 121 ms
55,628 KB
testcase_09 AC 121 ms
55,524 KB
testcase_10 AC 130 ms
55,764 KB
testcase_11 AC 164 ms
56,344 KB
testcase_12 AC 121 ms
56,164 KB
testcase_13 AC 152 ms
56,860 KB
testcase_14 AC 150 ms
56,812 KB
testcase_15 AC 121 ms
55,468 KB
testcase_16 AC 151 ms
56,940 KB
testcase_17 AC 121 ms
56,284 KB
testcase_18 AC 153 ms
56,740 KB
testcase_19 AC 122 ms
55,496 KB
testcase_20 AC 150 ms
57,004 KB
testcase_21 AC 152 ms
56,632 KB
testcase_22 AC 149 ms
56,848 KB
testcase_23 AC 150 ms
56,492 KB
testcase_24 AC 150 ms
56,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;

public class No55 {
//	private static Set<String> set = new HashSet<String>();
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] x = new int[3];
		int[] y = new int[3];
		for(int i = 0; i < 3; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}
//		for(int i = 0; i < 3; i++) {
//			System.out.println("x y = " + x[i] + " , " + y[i]);
//		}
		int x1, y1, x2, y2;
		boolean f = false;
		// 与えられた3点でのなす角を全て確認するため3回ループ
		for(int i = 0; i < 3; i++) {
			// ベクトル成分を考える。x0~x2のうち、x1を中心に考える。
			x1 = x[1] - x[0];
			y1 = y[1] - y[0];
			x2 = x[2] - x[1];
			y2 = y[2] - y[1];
			// ベクトルの内積が0、かつ長さが等しい場合は正方形の対角線でないため、フラグを立ててループを抜ける
			if((x1 * x2 + y1 * y2) == 0 && Math.pow(x1, 2) + Math.pow(y1, 2) == Math.pow(x2, 2) + Math.pow(y2, 2)) {
				f = true;
				break;
			}
			// 中心となる点を変更するため配列を入れ替える
			// 入れ替えるのは2回のみでOK。最後の一回は不要。
			if(i < 2) {
				int tmpx = x[i];
				x[i] = x[i+1];
				x[i+1] = tmpx;
				int tmpy = y[i];
				y[i] = y[i+1];
				y[i+1] = tmpy;
			}
		}
		// 正方形が描ける場合は座標を出力
		if(f) {
			// 正方形の対角線の交点は、対角線の中点
			// (x[0]+x[2])/2 , (y[0]+y[2])/2 = (x[1]+x?)/2 , (y[1]+y?)/2 を展開すると
			System.out.println((x[0]+x[2]-x[1]) + " " + (y[0]+y[2]-y[1]));
		}else {
			System.out.println(-1);
		}
	}
}
0