surrounded by a group nt attacks 8 squares as in a typical chess game, which are shown e figure - the knight on the red square attacks the 8 squares a red dot. The rook can move horizontally and vertically by number of squares. The rook can safely pass through an empty re that is attacked by a knight, but it must move to a square that t attacked by any knight. The rook cannot jump over a knight e moving. If the rook moves to a square that contains a knight, ay capture it and remove it from the board. The black knights r move. Can the rook eventually safely move to the designated et square? The figure illustrates how the white rook can move to the blue et square at the top-right corner in the first sample case. The captures one black knight at the bottom-right of the board on

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
On a chess board of r rows and c columns there is a lone white
rook surrounded by a group of opponent's black knights. Each
knight attacks 8 squares as in a typical chess game, which are shown
in the figure - the knight on the red square attacks the 8 squares
with a red dot. The rook can move horizontally and vertically by
any number of squares. The rook can safely pass through an empty
square that is attacked by a knight, but it must move to a square that
is not attacked by any knight. The rook cannot jump over a knight
while moving. If the rook moves to a square that contains a knight,
it may capture it and remove it from the board. The black knights.
never move. Can the rook eventually safely move to the designated
target square?
The figure illustrates how the white rook can move to the blue
target square at the top-right corner in the first sample case. The
rook captures one black knight at the bottom-right of the board on
its way.
Rok nd kight lcoes by Chunen
Input
The first line of input contains two integers r and c (2 <r,c< 750). Each of the next r lines describes one row of the
board using c characters: the letter 'R' represents the white rook, a 'K' represents a black knight, a dot '. represents
an empty square, and the letter 'T' represents the white rook's target square. There is exactly one 'R', exactly one 'T',
and at least one 'K' on the board. It is guaranteed that the white rook starts in a square that is not attacked by any
knight. The target square may be attacked by a knight, in which case the knight must be captured before the rook can
safely move to the target square.
Output
Output yes if the white rook can move to the target square, or no otherwise.
Sample Input 1
Sample Output 1
6 6
yes
.....T
..K.K.
К.к...
....K.
R..K..
....K.
Transcribed Image Text:On a chess board of r rows and c columns there is a lone white rook surrounded by a group of opponent's black knights. Each knight attacks 8 squares as in a typical chess game, which are shown in the figure - the knight on the red square attacks the 8 squares with a red dot. The rook can move horizontally and vertically by any number of squares. The rook can safely pass through an empty square that is attacked by a knight, but it must move to a square that is not attacked by any knight. The rook cannot jump over a knight while moving. If the rook moves to a square that contains a knight, it may capture it and remove it from the board. The black knights. never move. Can the rook eventually safely move to the designated target square? The figure illustrates how the white rook can move to the blue target square at the top-right corner in the first sample case. The rook captures one black knight at the bottom-right of the board on its way. Rok nd kight lcoes by Chunen Input The first line of input contains two integers r and c (2 <r,c< 750). Each of the next r lines describes one row of the board using c characters: the letter 'R' represents the white rook, a 'K' represents a black knight, a dot '. represents an empty square, and the letter 'T' represents the white rook's target square. There is exactly one 'R', exactly one 'T', and at least one 'K' on the board. It is guaranteed that the white rook starts in a square that is not attacked by any knight. The target square may be attacked by a knight, in which case the knight must be captured before the rook can safely move to the target square. Output Output yes if the white rook can move to the target square, or no otherwise. Sample Input 1 Sample Output 1 6 6 yes .....T ..K.K. К.к... ....K. R..K.. ....K.
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY