結果

問題 No.48 ロボットの操縦
ユーザー yo-kondo
提出日時 2018-03-10 19:55:47
言語 Go
(1.23.4)
結果
WA  
実行時間 -
コード長 1,260 bytes
コンパイル時間 14,539 ms
コンパイル使用メモリ 221,248 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-14 17:53:40
合計ジャッジ時間 11,605 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

// エントリポイント
func main() {
	in := bufio.NewScanner(os.Stdin)
	// 移動先の東西軸座標
	in.Scan()
	input1 := in.Text()
	// 移動先の南北軸座標
	in.Scan()
	input2 := in.Text()
	// ロボットが1命令につき前進することができる最大の距離
	in.Scan()
	input3 := in.Text()

	fmt.Println(maneuver(input1, input2, input3))
}

// 何回命令すれば目的地に到着できるか計算する。
func maneuver(eastWest string, northSouth string, distance string) string {
	e, _ := strconv.Atoi(eastWest)
	n, _ := strconv.Atoi(northSouth)
	d, _ := strconv.Atoi(distance)
	orderCount := 0

	eFloat := float64(e)
	nFloat := float64(n)
	dFloat := float64(d)

	// 先に進行の命令数を計算
	progressNS := int(math.Ceil(math.Abs(nFloat / dFloat)))
	progressEW := int(math.Ceil(math.Abs(eFloat / dFloat)))

	if n == 0 {
		// 東西のみ
		orderCount++
		orderCount += progressEW
	} else if n < 0 {
		// 先に東西に向かう
		orderCount++
		orderCount += progressEW
		orderCount++
		orderCount += progressNS
	} else {
		orderCount += progressNS
		if e != 0 {
			orderCount++
			orderCount += progressEW
		}
	}
	return strconv.Itoa(orderCount)
}
0