結果

問題 No.113 宝探し
ユーザー ayaaya
提出日時 2019-07-30 15:34:24
言語 PHP
(8.3.4)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 1,603 bytes
コンパイル時間 2,407 ms
コンパイル使用メモリ 32,144 KB
実行使用メモリ 32,404 KB
最終ジャッジ日時 2024-04-28 08:23:33
合計ジャッジ時間 4,397 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
32,144 KB
testcase_01 AC 41 ms
32,400 KB
testcase_02 AC 41 ms
32,400 KB
testcase_03 AC 40 ms
32,148 KB
testcase_04 AC 40 ms
32,400 KB
testcase_05 AC 40 ms
32,144 KB
testcase_06 AC 40 ms
32,148 KB
testcase_07 AC 40 ms
32,144 KB
testcase_08 AC 40 ms
32,272 KB
testcase_09 AC 39 ms
32,140 KB
testcase_10 AC 41 ms
32,272 KB
testcase_11 AC 41 ms
32,272 KB
testcase_12 AC 40 ms
32,400 KB
testcase_13 AC 40 ms
32,396 KB
testcase_14 AC 41 ms
32,212 KB
testcase_15 AC 40 ms
32,276 KB
testcase_16 AC 40 ms
32,404 KB
testcase_17 AC 41 ms
32,144 KB
testcase_18 AC 41 ms
32,148 KB
testcase_19 AC 41 ms
32,400 KB
testcase_20 AC 41 ms
32,400 KB
testcase_21 AC 40 ms
32,272 KB
testcase_22 AC 41 ms
32,020 KB
testcase_23 AC 41 ms
32,272 KB
testcase_24 AC 42 ms
32,144 KB
testcase_25 AC 40 ms
32,088 KB
testcase_26 AC 41 ms
31,960 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
/*
No.113 宝探し
問題文
A君は宝の地図を手に入れました。
地図には公園があり公園の中心に目印が書いてありました。
そして、そこからの移動方法が書いてありました。
書いてある文字に対応する移動方法は次のようになります。

・「N」は北に1メートル移動する。
・「E」は東に1メートル移動する。
・「W」は西に1メートル移動する。
・「S」は南に1メートル移動する。

例えば、「NE」と書いてあるなら北に1メートル歩いたのち東に1メートル歩きます。
その地点を掘れば宝が出てくるようです。
しかし、A君は移動方法の無駄に気づきました。
「NE」であれば北東の方向に12+12−−−−−−√=2–√メートルだけ移動すれば良さそうです。
A君は公園の中心から最短の距離で宝が埋まっている位置に移動したいです。
障害物にぶつかる可能性は無いとして、A君は何メートル移動する必要があるでしょうか?

入力
S
地図に書かれた文字列Sが1行で与えられる。
文字列Sの長さは1文字以上100文字以内である。
文字列は'N','E','W','S'の4文字のみから構成される。


*/

$input=str_split(trim(fgets(STDIN)));
$x=0;
$y=0;
foreach($input as $value){
  switch($value){
    case "N":
      $y++;
      break;
    case "S":
      $y--;
      break;
    case "E":
      $x++;
      break;
    case "W":
      $x--;
      break;
  }
}
echo round(sqrt(($x*$x)+($y*$y)),5);
?>
0