Home > Back-end >  This topic how to solve the two-dimensional array ah, please, brother
This topic how to solve the two-dimensional array ah, please, brother

Time:09-24

As shown, the sample input is
3 3
3 1 1
0 0 1
0 0 2
Output 4

CodePudding user response:

First reaction is breadth-first search,,, the an is konjac, squatting a bosses together

CodePudding user response:

Seems to be understandable for two-way flood coloring problem
1, from the point of departure is shaded, in four directions walk, walk in the steps for the current, is shaded with a new starting point to continue coloring,
2, from the end reverse coloring, in four directions walk, walk in the steps for the current, is shaded with new finish continue to coloring,
3, the boundary of the two shaded path, there are a lot of steps, add the smallest to the unicom, is the shortest path,
Shaded, if the current path didn't hit a wall, you can hit a wall, is coloring on "1" barriers, the current color behavior end when you meet for the first time, hit a wall and