[ad_1]
We have an NxM grid, grid have one element named Bob. Bob can travel diagonally blocks only. The grid has some blocked blocks on which Bob can not travel. Write a function that returns on how many possible positions Bob can move. Solve this problem using BFS and submit the executable code in any programming language. In the following image example, Bob's positioning is at 9,3, and it can visit the places where Y is marked; hence your method should return 31 What I have tried: used grid method .. <pre>public class Grid{ public static void main(String args[]){ int[][] gridData = { {0,0,0,0,0,0,0,0}, {0,1,0,0,0,1,0,0}, {0,0,0,0,1,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,1,0,0,1,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,1,0}, {0,0,1,0,0,1,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,2,1,0,0,0}}; //2 is bobs position, 1 is blocked, 0 can be visited Map grid = new Map(gridData); MapHelper solution = new MapHelper(); System.out.println(solution.countReachableCells(grid));
解決策 1
最初にアルゴリズムを注意深く調べます (ここでスターター: 幅優先検索 – ウィキペディア[^])、それから自分で実装してみてください。
最終的に行き詰まった場合は、ここで質問してください (詳細な入力例を提供する場合があります)。
[ad_2]
コメント