eolymp
bolt
Try our new interface for solving problems
Məsələlər

Full Board

Full Board

A game starts with an \textbf{M}×\textbf{N} board with some squares marked as "obstacles" (drawn as dark squares in the figure below). The player chooses a starting position for a ball (drawn as solid gray dot) and chooses a direction (up, down, left, or right) to advance. Once the direction is chosen, the ball will advance in that direction until it hits an obstacle, the boundary of the board, or its own trajectory. When it hits one of these, the ball stops. Then the player is allowed to choose another direction, and the ball will advance in the same manner. The game ends when no legal move can be made. The player wins if and only if the trajectory includes all the empty squares on the board. The figure below traces a trajectory that shows one way to win the game in \textbf{10} steps. \includegraphics{https://static.e-olymp.com/content/e1/e1266c47eba1a0f578f4f3f4ab9ae1fc8892f02c.jpg} Given an initial setting of a board, write a program to calculate the minimum number of steps to win the game. \InputFile Each case on the input file begins with two integers \textbf{m} and \textbf{n} (\textbf{1} ≤ \textbf{m}, \textbf{n} ≤ \textbf{30}), indicating the size of board. The next \textbf{m }lines describe the initial setting of the board. Each line contains \textbf{n} characters, either '\textbf{*}' or '\textbf{.}', indicating if the corresponding square is an obstacle or empty, respectively. \[For example, see below for the input file corresponding to the case in the figure above.\] It is guaranteed that the initial board is not fully covered by obstacles. Process until end-of-file; there is no end of data flag. \OutputFile Output the minimum number of steps to cover the board. Follow the format exactly: "\textbf{Case}", one space, the case number, a colon and one space, and one integer indicating the minimum number of steps to win the game, or if there is no way to win, the number \textbf{-1}. Do not print any trailing spaces.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
5 5
**...
.....
....*
..*..
.....
Çıxış verilənləri #1
Case 1: 10
Mənbə ACM ICPC NCNA Programming Contest - November 7, 2013