luogu#P2346. 四子连棋

    ID: 1339 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>搜索启发式搜索启发式迭代加深搜索 IDA*

四子连棋

Background

The input testdata for this problem contains \r\n; please use cin or scanf for input.

Problem Description

On a 4×44\times 4 board there are 1414 pieces: 77 white and 77 black, with two empty cells. Any piece may move up, down, left, or right into an adjacent empty cell; this counts as one move. Black and white move alternately, and either side may move first. If at any time the pieces of either color form four in a line (including diagonals), that state is a target board position.

Input Format

Read a 4×44\times 4 initial board from the file. Black pieces are denoted by B, white pieces by W, and empty cells by O.

Output Format

Output the minimum number of moves required to reach a target board position.

BWBO
WBWB
BWBW
WBWO
5

Hint

Translated by ChatGPT 5