mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-05 22:59:31 +08:00
添加0126.骑士的攻击astar C语言 版本
This commit is contained in:
@ -500,7 +500,7 @@ int astar(int start_x, int start_y, int goal_x, int goal_y) {
|
||||
Knight start;
|
||||
start.x = start_x;
|
||||
start.y = start_y;
|
||||
start.g = 0; // 从起点到起点的消耗为 0
|
||||
start.g = 0;
|
||||
start.h = heuristic(start_x, start_y, goal_x, goal_y);
|
||||
start.f = start.g + start.h; // 总的估计消耗
|
||||
|
||||
@ -547,7 +547,7 @@ int main() {
|
||||
scanf("%d %d %d %d", &a1, &a2, &b1, &b2);
|
||||
|
||||
int result = astar(a1, a2, b1, b2); // 使用 A* 算法计算最短路径
|
||||
printf("%d\n", result); // 输出所需的最小移动次数
|
||||
printf("%d\n", result); // 输出最小移动次数
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user