you have haspital with M X N number of rooms.suddenly bacterial infection occurs in one room and its starts spreading in north,south, west, east direction and only to its adjacent room which is opened .find how long would take for the bacteria to be spread to the entire hospital
Answers
Explanation
This Question is Literally Incomplete.
Answer:I have a logic try this.
Explanation:
Entering a bacteria into one room takes one min. First they given bacteria entered room so to fill that room takes 1min. Now the initial time is 1min.
Mxn matrix
After that we have position of bacteria. And at a time it can travel in all directions up,down,right and left so we check the whether room is open or close . If it is open now we have to close. Then check which point has next highest open rooms .then go to that position and iterate this process. For every iteration time is incremented and final time is printed.
Logic that I have tried is posted as picture .
Please try to think it's simple program
Step1: make position of bacteria to close room
Step2: make up,down,right,left position of bacteria to close room.
Step 3: now you have to note down the position of up,down,right and left of bacteria in a list.
Step 4: Now count the which positions adjacent side have highest open room . I mean if position is up then check up,right,left,down to that position note as count . Same way calculate the count of all positions and which has highest count note it as next point .
Step 5: when count is zero break loop.
Step 6: make loop of step 1,2,3,4,5