Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 03. Knight Game
- # Multidimensional Lists - Exercise 2
- # https://judge.softuni.org/Contests/Practice/Index/3194#2
- def is_inside_func(current_row, current_col, default_M_size):
- return 0 <= current_row < default_M_size and 0 <= current_col < default_M_size
- size = int(input())
- M = []
- for _ in range(size):
- M.append(list(input()))
- removed_knights = 0
- while True:
- table = {}
- for row in range(len(M)):
- for col in range(len(M)):
- if M[row][col] == '0':
- continue
- if is_inside_func(row - 2, col + 1, size) and M[row - 2][col + 1] == 'K': # DIAGONAL TOP RIGHT #1
- if (row, col) not in table:
- table[(row, col)] = 0
- table[(row, col)] += 1
- if is_inside_func(row - 1, col + 2, size) and M[row - 1][col + 2] == 'K': # DIAGONAL TOP RIGHT #2
- if (row, col) not in table:
- table[(row, col)] = 0
- table[(row, col)] += 1
- if is_inside_func(row + 1, col + 2, size) and M[row + 1][col + 2] == 'K': # DIAGONAL BOTTOM RIGHT #1
- if (row, col) not in table:
- table[(row, col)] = 0
- table[(row, col)] += 1
- if is_inside_func(row + 2, col + 1, size) and M[row + 2][col + 1] == 'K': # DIAGONAL BOTTOM RIGHT #2
- if (row, col) not in table:
- table[(row, col)] = 0
- table[(row, col)] += 1
- if is_inside_func(row + 2, col - 1, size) and M[row + 2][col - 1] == 'K': # DIAGONAL BOTTOM LEFT #1
- if (row, col) not in table:
- table[(row, col)] = 0
- table[(row, col)] += 1
- if is_inside_func(row + 1, col - 2, size) and M[row + 1][col - 2] == 'K': # DIAGONAL BOTTOM LEFT #2
- if (row, col) not in table:
- table[(row, col)] = 0
- table[(row, col)] += 1
- if is_inside_func(row - 1, col - 2, size) and M[row - 1][col - 2] == 'K': # DIAGONAL TOP LEFT #1
- if (row, col) not in table:
- table[(row, col)] = 0
- table[(row, col)] += 1
- if is_inside_func(row - 2, col - 1, size) and M[row - 2][col - 1] == 'K': # DIAGONAL TOP LEFT #2
- if (row, col) not in table:
- table[(row, col)] = 0
- table[(row, col)] += 1
- if len(table) == 0:
- break
- most_attacks = 0
- knight_row, knight_col = 0, 0
- for position, attacks in table.items():
- if attacks > most_attacks:
- most_attacks = attacks
- knight_row = position[0]
- knight_col = position[1]
- M[knight_row][knight_col] = '0' # Remove the most danger Knight
- removed_knights += 1
- print(removed_knights)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement