Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def next_moves(k_row, k_col, size):
- next_possible_moves = []
- valid_range = range(0, size)
- if k_row - 1 in valid_range and k_col - 2 in valid_range:
- next_possible_moves.append((k_row - 1, k_col - 2))
- if k_row - 2 in valid_range and k_col - 1 in valid_range:
- next_possible_moves.append((k_row - 2, k_col - 1))
- if k_row - 2 in valid_range and k_col + 1 in valid_range:
- next_possible_moves.append((k_row - 2, k_col + 1))
- if k_row - 1 in valid_range and k_col + 2 in valid_range:
- next_possible_moves.append((k_row - 1, k_col + 2))
- if k_row + 1 in valid_range and k_col - 2 in valid_range:
- next_possible_moves.append((k_row + 1, k_col - 2))
- if k_row + 2 in valid_range and k_col - 1 in valid_range:
- next_possible_moves.append((k_row + 2, k_col - 1))
- if k_row + 2 in valid_range and k_col + 1 in valid_range:
- next_possible_moves.append((k_row + 2, k_col + 1))
- if k_row + 1 in valid_range and k_col + 2 in valid_range:
- next_possible_moves.append((k_row + 1, k_col + 2))
- return next_possible_moves
- rows = int(input())
- knights_coordinates = []
- removed_knights = 0
- max_knight = {}
- matrix = []
- for row in range(rows):
- current_row = list(input())
- matrix.append(current_row)
- for col in range(len(current_row)):
- if matrix[row][col] == "K":
- knights_coordinates.append((row, col))
- while True:
- max_knight = {}
- max_knight_hits = 0
- max_knight_row, max_knight_col = None, None
- for knight_row, knight_col in knights_coordinates:
- hit_knights = 0
- next_possible_move = next_moves(knight_row, knight_col, rows)
- for next_row, next_col in next_possible_move:
- if matrix[next_row][next_col] == "K":
- hit_knights += 1
- if hit_knights:
- max_knight[(knight_row, knight_col)] = hit_knights
- if hit_knights > max_knight_hits:
- max_knight_hits = hit_knights
- max_knight_row, max_knight_col = knight_row, knight_col
- if max_knight:
- knights_coordinates.remove((max_knight_row, max_knight_col))
- removed_knights += 1
- matrix[max_knight_row][max_knight_col] = "0"
- else:
- break
- print(removed_knights)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement