Answered step by step
Verified Expert Solution
Question
1 Approved Answer
def simulate _ water _ flow ( matrix ) : n = len ( matrix ) water _ level = matrix [ n / /
def simulatewaterflowmatrix:
n lenmatrix
waterlevel matrixn n
while True:
for i in rangen:
for j in rangen:
if matrixij waterlevel:
if i and matrixi j:
matrixi jW
if i n and matrixi j:
matrixi jW
if j and matrixij :
matrixij W
if j n and matrixij :
matrixij W
if allcell for row in matrix for cell in row:
break
waterlevel
return matrix
# Input reading
n intinput
terrainmatrix listmapint inputsplit for in rangen
# Call the simulation function
resultmatrix simulatewaterflowterrainmatrix
# Print the result
for row in resultmatrix:
printjoinmapstr row
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started