注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
如果对你有帮助,真的求米!!!!不会消耗你的米,感谢感谢
我感觉挺难的,ng的oa居然一个mid一个hard,哭死。之前看有帖子说是力扣原题,但其实不是的,还要比原题难一丢丢。不过思路差不多
第一题
1. Avoiding the monsters
In this game, a player begins on a two-dimensional grid of size n x m. One cell of the grid is marked as the end and th player wants to reach this cell in the grid by moving up, down, left or right. However, some cells are occupied by monsters. The goal of the player is to reach the end cell using a path that maximizes the minimum distance from any monster along that path.
The distance between any two points on the grid with coordinates (X1, y1) and (X2. Y2) is calculated as |x1 - x2l + ly1-y2l. where |a| is the absolute value of integer a.
Notes:
1.One can visit a cell with a monster if necessary, i.e. no other path exists.
2.A cell can be visited only once on a given path.
Function Description
Complete the function findBestPath in the editor below.
findBestPath has the following parameters:
int n: the number of rows in the grid
int m: the number of columns in the grid
int startRow: the row index of the starting position
int startColumn: the column index of the starting position
int endRow: the row index of the ending position
int endColumn: the column index of the ending position
int monsterRow: the row index of the ith monster
int monsterColumn[i]: the column index of the ith monster
Returns
int: the largest possible minimum distance from a monster in any path from the starting point to the ending point
Function Description
Complete the function findBestPath in the editor below.
findBestPath has the following parameters:
int n: the number of rows in the grid
int m: the number of columns in the grid
int startRow: the row index of the starting position
int startColumn: the column index of the starting position
int endRow: the row ine 1
Sample Input For Custom Testing
STDIN Function
5→arrival[] size n = 5
0→arrival = [0, 1, 1, 3, 3]
1
1
3
3
5→direction[] size n = 5
0→direction = [0, 1, 0, Θ, 1]
1
0
0
1
Sample Output:
0
2
1
4
3
Explanation
Explanation 1
At time 0, hiker 0 passes through the narrow portion of the trail (ascending).
At time 1, hikers 1 (descending) and 2 (ascending) want to pass through the narrow portion of the trail, and hiker 2 passes through because an ascending hiker passed through in the previous second.
At time 2, hiker 1 (descending) passes through the as there no other ascending hikers waiting.
At time 3, hiker 3 (ascending) and 4 (descending) want to pass through. Hiker 4 passes through because at the previous second another descending hiker passed through.
At time 4, hiker 3 passes through.
如果对你有帮助,真的求米!!!!不会消耗你的米,感谢感谢 |