The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 1 Day Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
Gas leakages at chemical plants might prove to be fatal and put the lives of the workers at risk.
Â
The aim is to detect the leakage of a gas and prevent its explosion. Our friend Ramesh has successfully obtained the tender to set up a chemical plant to supply fertilizers to the nearby villages. A magnanimous person by heart, he has always put the welfare of the workers above all. So, safety measures have to be taken.
Â
For that worst case possibility is considered here.
Â
The rooms of the plant can be modelled as axb matrix. The gas used in his plant has a queer property.
Â
In times of its leakage, it expands according to the following rules:
Â
If at time t, gas leaks from room (x ,y), then at time t+1 it can breaks the doors of atmost two more rooms out of (x+1,y), (x-1,y), (x,y+1), (x,y-1) and expands.
Â
For example if at t = 0 sec if the gas occupies (2, 3), then at time t = 1 sec, the rooms filled with gas can be any of the given 6 possibilities:
1. Rooms at (2,3), (3,3) and (2,4). 2. Rooms at (2,3), (3,3) and (1,3). 3. Rooms at (2,3), (3,3) and (2,2). 4. Rooms at (2,3), (2,4) and (1,3). 5. Rooms at (2,3), (2,4) and (2,2). 6. Rooms at (2,3), (2,2) and (1,3). Note: At t= 2 sec, it can expand from all the rooms that are full of gas t= 1.
The gas explodes after gas fills all the rooms and there is no room for it to expand.
Find the minimum time gas takes for the whole plant to explode and help Ramesh ensure the safety of his workers.
Â
Â
T - The number of test cases.
Â
a b - number of row and columns in the room matrix.
Â
x y- coordinate of the room where the gas leaked first.
Â
Â
The minimum time in seconds the plant take to explode.
Â
1
Input: 2 9 9 2 6 1 1 1 1 Output: 12 0
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll