final commit
This commit is contained in:
+25
-25
@@ -2,30 +2,7 @@
|
||||
grid_map = []
|
||||
min_distances = []
|
||||
|
||||
def main():
|
||||
global grid_map, min_distances
|
||||
# Create a 9x9 grid map filled with '.'
|
||||
grid_map = [['.' for temp in range(9)] for temp in range(9)]
|
||||
# Create a minimum distance grid with initial values set to "infinity" (10000)
|
||||
min_distances = [[10000 for temp in range(9)] for temp in range(9)]
|
||||
|
||||
# Read perception variant
|
||||
variant = int(input())
|
||||
# Read Keymaker's position
|
||||
position_input = input().split()
|
||||
keymaker_x = int(position_input[0])
|
||||
keymaker_y = int(position_input[1])
|
||||
|
||||
# Set the starting position (0, 0) with a minimum distance of 0
|
||||
min_distances[0][0] = 0
|
||||
# Start the recursive pathfinding search from the starting position
|
||||
find_path(0, 0)
|
||||
|
||||
# Output the result based on the minimum distance to the Keymaker's position
|
||||
if min_distances[keymaker_y][keymaker_x] == 10000:
|
||||
print("e -1") # If no path is found, output -1
|
||||
else:
|
||||
print("e " + str(min_distances[keymaker_y][keymaker_x])) # Output the shortest path length
|
||||
|
||||
def observe(x, y):
|
||||
# Sends a move command and receives information on perceived cells around position (x, y)
|
||||
@@ -73,5 +50,28 @@ def find_path(x, y):
|
||||
|
||||
observe(x, y) # Final exploration after checking all directions.
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
# Create a 9x9 grid map filled with '.'
|
||||
grid_map = [['.' for temp in range(9)] for temp in range(9)]
|
||||
# Create a minimum distance grid with initial values set to "infinity" (10000)
|
||||
min_distances = [[10000 for temp in range(9)] for temp in range(9)]
|
||||
|
||||
# Read perception variant
|
||||
variant = int(input())
|
||||
# Read Keymaker's position
|
||||
position_input = input().split()
|
||||
keymaker_x = int(position_input[0])
|
||||
keymaker_y = int(position_input[1])
|
||||
|
||||
# Set the starting position (0, 0) with a minimum distance of 0
|
||||
min_distances[0][0] = 0
|
||||
# Start the recursive pathfinding search from the starting position
|
||||
find_path(0, 0)
|
||||
|
||||
# Output the result based on the minimum distance to the Keymaker's position
|
||||
if min_distances[keymaker_y][keymaker_x] == 10000:
|
||||
print("e -1") # If no path is found, output -1
|
||||
else:
|
||||
print("e " + str(min_distances[keymaker_y][keymaker_x])) # Output the shortest path length
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user