QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 2048 MB Total points: 100

#14440. Carl 的迷宮求解演算法

Statistics

螞蟻 Carl 回來了!在遊歷過一些金字塔後,Carl 決定研究一些演算法,並發明了一種用於解決網格迷宮的新穎演算法。其運作方式如下:

  • Carl 從迷宮中的某個位置開始,面向右方,並希望到達目的地格子。
  • 當 Carl 還未到達目的地格子時:
    • 如果 Carl 可以向左轉 90 度並面對一個空地,他會向左轉 90 度,然後向前移動一格。
    • 否則,如果 Carl 可以向前移動一格,他就會向前移動。
    • 否則,他會向右轉 90 度。

Carl 想知道這個演算法是否有效。請幫他檢查!

輸入格式

輸入的第一行包含兩個整數 $r$ 和 $c$ ($1 \le r, c \le 50$),表示迷宮的大小(列數、行數)。格子 $(1, 1)$ 是迷宮的左上角。

下一行包含兩個整數 $i_{start}$ 和 $j_{start}$ ($1 \le i_{start} \le r, 1 \le j_{start} \le c$),表示 Carl 的起始位置,位於第 $i_{start}$ 列、第 $j_{start}$ 行。

下一行包含兩個整數 $i_{end}$ 和 $j_{end}$ ($1 \le i_{end} \le r, 1 \le j_{end} \le c$),表示 Carl 想要的終點位置,位於第 $i_{end}$ 列、第 $j_{end}$ 行。保證 Carl 的起始位置與終點位置不同。

接下來的 $r$ 行,每行包含一個長度為 $c$ 的字串,僅由 0 或 1 組成。如果字元為 1,則該格子有障礙物且無法通過,否則該格子為空地。保證 Carl 的起始位置與終點位置皆為空地。

輸出格式

輸出一個整數,如果 Carl 可以從起始位置到達終點位置,則輸出 1,否則輸出 0。

範例

範例輸入 1

4 5
1 1
4 5
00111
10100
10111
10000

範例輸出 1

1

範例輸入 2

3 3
1 1
3 3
001
001
110

範例輸出 2

0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.