Question: Both a spider and a fly got interested in a doughnut, although for different reasons. Flies sit on the doughnut and try to eat the

 Both a spider and a fly got interested in a doughnut,

Both a spider and a fly got interested in a doughnut, although for different reasons. Flies sit on the doughnut and try to eat the doughnut and sugar covering it, and the spider tries to catch the fly. The spider lands on the doughnut and starts moving searching for flies. To make this problem more innocent, let's think about a computer game. There is a torus covered with an n by m mesh of "squares". Each square is covered with sugar powder (marked with a letter S), or is just dough (letter D). On one or more of those squares sit flies (these squares are marked with F). Your task is to decide if a spider that lands on square with coordinates (r.c) can catch a fly. The spider can only move on non-sugar squares (otherwise it gets stuck). Flies busy with eating do not move at all. Your task: given the row and column coordinates of a grid cell can the spider find a fly? You are to write a program to answer this question. Input Specification The input consists of 0 0 lines each containing a pair of integers i and j. The first n lines will represent the n by m grid covering the doughnut where a 'S'/'D/F' at the c-character of the r-th line indicates sugar/dough/fly within the square at row r and column c of the grid. The pairs of integers on the last k lines each represent the row and column coordinates of some grid cell. Output Specification The output for each pair of integers, ii and j, on the last k lines of input consists of a word on a separate line, indicating if the spider can reach/find a fly: YES, or NO. Sample Input DDDSDDSD DDDSDDSD DDDSDDSD DFDSCOSD DDDSDDSD DDDSDDSS DDDSDDSD 7 8 4 5 Output: YES NO Both a spider and a fly got interested in a doughnut, although for different reasons. Flies sit on the doughnut and try to eat the doughnut and sugar covering it, and the spider tries to catch the fly. The spider lands on the doughnut and starts moving searching for flies. To make this problem more innocent, let's think about a computer game. There is a torus covered with an n by m mesh of "squares". Each square is covered with sugar powder (marked with a letter S), or is just dough (letter D). On one or more of those squares sit flies (these squares are marked with F). Your task is to decide if a spider that lands on square with coordinates (r.c) can catch a fly. The spider can only move on non-sugar squares (otherwise it gets stuck). Flies busy with eating do not move at all. Your task: given the row and column coordinates of a grid cell can the spider find a fly? You are to write a program to answer this question. Input Specification The input consists of 0 0 lines each containing a pair of integers i and j. The first n lines will represent the n by m grid covering the doughnut where a 'S'/'D/F' at the c-character of the r-th line indicates sugar/dough/fly within the square at row r and column c of the grid. The pairs of integers on the last k lines each represent the row and column coordinates of some grid cell. Output Specification The output for each pair of integers, ii and j, on the last k lines of input consists of a word on a separate line, indicating if the spider can reach/find a fly: YES, or NO. Sample Input DDDSDDSD DDDSDDSD DDDSDDSD DFDSCOSD DDDSDDSD DDDSDDSS DDDSDDSD 7 8 4 5 Output: YES NO

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!