QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 512 MB 總分: 100 难度: [顯示]

#1811. 如何移動豆子

统计

有一個由 $H$ 列與 $W$ 行組成的網格。該網格是圓柱形的:它的左側與右側相連,因此第 $1$ 行與第 $W$ 行互為鄰居。

網格中的某些方格放置了盤子,而豆子則放置在其中一些盤子上,初始時每個盤子至多包含一顆豆子。在遊戲過程中,一個盤子允許包含任意數量的豆子。

Alice 與 Bob 在這個網格上輪流進行遊戲。Alice 先手。在每一回合中,玩家可以選擇任意一顆豆子,假設其當前位置為 $(r, c)$,並根據以下規則移動它:

  • 豆子只能移動到放置有盤子的方格。
  • 豆子不能移動到該特定豆子曾經到達過的方格(所有豆子皆可區分)。
  • 從 $(r, c)$ 出發,豆子可以移動到下方一格(移動至 $(r + 1, c)$,僅在 $r < H$ 時可行)、右方一格(若 $c < W$ 則移動至 $(r, c + 1)$,若 $c = W$ 則移動至 $(r, 1)$),或左方一格(若 $c > 1$ 則移動至 $(r, c - 1)$,若 $c = 1$ 則移動至 $(r, W)$)。

無法移動任何豆子的玩家即輸掉遊戲。

請判斷若雙方皆採取最佳策略,誰將獲勝。

輸入格式

第一行包含兩個整數 $H$ 與 $W$ ($1 \le H, W \le 1000$)。

接下來是初始網格的描述,包含 $H$ 行,每行包含一個長度為 $W$ 的字串。第 $i$ 行的第 $j$ 個字元若為 '#' 表示方格 $(i, j)$ 沒有盤子;若為 '.' 表示該方格有一個空盤子;若為 'B' 表示該方格有一個放了一顆豆子的盤子。題目不保證網格中一定包含這三種字元(例如,沒有豆子的網格也是合法的)。

輸出格式

若 Alice 在雙方採取最佳策略下獲勝,請輸出 "Alice"。否則,請輸出 "Bob"。

範例

範例輸入 1

2 3
B.#
#..

範例輸出 1

Alice

範例輸入 2

1 1
B

範例輸出 2

Bob

範例輸入 3

1 3
B#.

範例輸出 3

Alice

說明

在第一個範例中,唯一的豆子初始位於 $(1, 1)$。Alice 將其移動至 $(1, 2)$。Bob 唯一的移動是將其移至 $(2, 2)$,接著 Alice 將豆子移至 $(2, 3)$,此時 Bob 無法再進行任何移動,因此 Alice 獲勝。

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.