0114. The King and the Rook
Имя входного файла: | kingrook.in |
Имя выходного файла: | kingrook.out |
Ограничение по времени: | 2 s |
Ограничение по памяти: | 64 megabytes |
You are given a small chessboard 6*6. There are three pieces on it: a White King, a White Rook and a Black King. Your task is to calculate the minimal number of moves required for both sides to checkmate the Black King or determine that it is impossible or that the position is incorrect.
Input file
The only line of the input file contains three coordinates of fields – coordinates of White King, White Rook and Black King respectively, followed by an identifier of the side to move (W for white or B for black).
Output file
Write to the output file total number of moves (for both sides) required for white to win the game. If the black king is already checkmated, output 0. If the input position is incorrect (two kings are adjacent or it is white move and the check is declared for black), output -1. If the game will end in a draw (e.g. black are stalemated), output -2.
Examples:
kingrook.in | kingrook.out |
---|---|
c6 f4 a5 B | 2 |
c6 f4 b5 W | -1 |
Источник: Petrozavodsk Summer 2003. Primary Contest, Sunday, August 24
Автор: Andrew Lopatin, Nick Durov
Обсудить Отправить решение
Версия для печати