Wesam and Omar

4

2 votes
Basics of Greedy Algorithms, Algorithms, Greedy Algorithms
Problem

You are given a grid of size 3*3 that has the following specifications:

  • Each cell in the grid is either empty '.' or occupied '*'.
  • you can't move to an occupied cell.
  • Wesam starts at cell (1,1) and wants to reach Omar who is in cell (3,3).
  • Wesam can move vertically, horizontally, and diagonally.

Note:If Wesam is standing at cell (x,y), he can go to :(x+1,y) , (x-1,y), (x,y+1) , (x,y-1), (x+1,y+1) , (x-1,y-1).

Note: rows are numbered from top to down, and columns are numbered from left to right.

Write a program to find if Wesam can reach Omar or not.

Input format:

  • First line: T (number of test cases)
    For each test case
  • 3 lines: 3 characters (denoting each cell in the grid.

It's guaranteed that cell (1,1) and cell (3,3) are empty.

Output format:

For each test case print "YES" (without quotes) if Wesam can reach Omar. Print "NO" (without quotes) otherwise.

Constraints

1<= T <= 100

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the first test:

Editor Image

?