結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー tsuchinagatsuchinaga
提出日時 2019-04-01 15:08:14
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 925 bytes
コンパイル時間 11,426 ms
コンパイル使用メモリ 222,388 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-03 21:48:05
合計ジャッジ時間 12,326 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
)

func main() {
	var x1, y1, x2, y2, x3, y3 float64
	_, _ = fmt.Scan(&x1, &y1, &x2, &y2, &x3, &y3)

	sa := (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)
	sb := (x2-x3)*(x2-x3) + (y2-y3)*(y2-y3)
	sc := (x3-x1)*(x3-x1) + (y3-y1)*(y3-y1)

	fmt.Println(sa, sb, sc)

	// 3辺の長さがすべて同じか、すべて違う場合は正方形を作れない
	if (sa == sb && sb == sc && sc == sa) || (sa != sb && sb != sc && sc != sa) {
		fmt.Println(-1)
		return
	}

	// 4つ目の点の位置
	var x4, y4 float64
	if sa == sb && sa*2 == sc {
		x4, y4 = x3+x1-x2, y3+y1-y2
	} else if sb == sc && sb*2 == sa {
		x4, y4 = x1+x2-x3, y1+y2-y3
	} else if sc == sa && sc*2 == sb {
		x4, y4 = x2+x3-x1, y2+y3-y1
	}
	// fmt.Println(x4, y4)

	// 方眼紙にかけるか = 整数かのチェック
	if x4 == float64(int(x4)) && y4 == float64(int(y4)) {
		fmt.Printf("%.0f %.0f", x4, y4)
	} else {
		fmt.Println(-1)
	}
}
0