QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22355. 西洋跳棋

Statistics

母牛們熱衷於西洋跳棋。雖然玩得無比快樂,她們卻很不擅長殘局,想請你幫助。

給定 $N\times N$、$(4 \le N \le 30)$ 的棋盤,求在下一回合結束遊戲的最佳走法序列。棋子只在 + 格移動,跳過對方棋子即可吃子,被跳過的棋子立即移除。以下是 $N=8$ 的例子:

- + - + - + - +
+ - + - + - + -
- + - K - + - +
+ - + - + - + -
- o - o - + - +
+ - K - + - + -
- o - + - + - +
+ - K - + - K -

K 是 Bessie 的王棋,o 是對手棋子。總由 Bessie 接著走。王棋可沿任意對角方向連續跳過對手棋子,跳過即移除。此盤需左下方王棋連續跳過全部三個對手棋子,結束遊戲;移動的 K 標為 >K<。

- + - + - + - +     - + - + - + - +    - + - + - + - +     - + - + - + - +
+ - + - + - + -     + - + - + - + -    + - + - + - + -     + - + - + - + -
- + - K - + - +     - + - K - + - +    - + - K - + - +     - + - K - + - +
+ - + - + - + -     + - + - + - + -    + ->K<- + - + -     + - + - + - + -
- o - o - + - +     - o - o - + - +    - + - o - + - +     - + - + - + - +
+ - K - + - + -    >K<- K - + - + -    + - K - + - + -     + - K ->K<- + -
- o - + - + - +     - + - + - + - +    - + - + - + - +     - + - + - + - +
+ ->K<- + - K -     + - + - + - K -    + - K - + - K -     + - K - + - K -

從左到右:初始、移動 1 後、移動 2 後、移動 3 後。

這些走法經過以下格子:

  1 2 3 4 5 6 7 8
1 - + - + - + - +
2 + - + - + - + -
3 - + - K - + - +
4 + - * - + - + -
5 - o - o - + - +
6 * - K - * - + -
7 - o - + - + - +
8 + - K - + - K -

行、列;起點:$(8,3)$;移動:$(6,1)$、$(4,3)$、$(6,5)$。

編程判斷給定 $N\times N$ 棋盤是否存在結束遊戲的序列,並找出該序列(若存在,實際上是唯一的)。棋盤上至少有一個王棋及一個對方棋子。

輸入格式

  • 第 1 行:一個整數 $N$。

  • 第 $2,\ldots,N+1$ 行:第 $i+1$ 行有 $N$ 個字元,每個為 -、+、K 或 o,表示合法棋盤的第 $i$ 行。

輸出格式

  • 第 1 行起:若不存在該序列,單獨一行輸出 impossible。否則每行兩個空格分隔整數,表示能獲勝的一個王棋依次所在的位置。

範例

輸入格式 1

8
-+-+-+-+
+-+-+-+-
-+-K-+-+
+-+-+-+-
-o-o-+-+
+-K-+-+-
-o-+-+-+
+-K-+-K-

輸出格式 1

8 3
6 1
4 3
6 5

題目作者:Rob Kolstad,2008

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.