Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions

Question

Time that the team will stay together (team lifetime)

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago