Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Bitnami MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
0726 - Acoperire 1
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
= Exemplu: = <code>acoperire1.in</code> 6 <code>acoperire1.out</code> 0 7 2 2 2 0 3 7 2 4 4 4 3 7 7 4 5 5 3 3 6 1 1 5 6 6 6 8 1 5 0 8 8 8 1 0 <syntaxhighlight lang="python" line="1"> def place_l_tiles(board, n, top_left_row, top_left_col): # n - dimension of the current board (n x n) if n == 2: # Base case: only one tile can fit, as 4 cells are considered and one corner is missing for i in range(2): for j in range(2): if board[top_left_row + i][top_left_col + j] == 0: board[top_left_row + i][top_left_col + j] = 1 return half = n // 2 # Find the center tile to place the L-shaped tromino around # (middle of the top-left, top-right, bottom-left, bottom-right quarters) center_r, center_c = top_left_row + half - 1, top_left_col + half - 1 # Determine which quadrant is missing the corner cell if board[top_left_row][top_left_col] == -1: missing_quad = 0 elif board[top_left_row][top_left_col + n - 1] == -1: missing_quad = 1 elif board[top_left_row + n - 1][top_left_col] == -1: missing_quad = 2 elif board[top_left_row + n - 1][top_left_col + n - 1] == -1: missing_quad = 3 # Fill the center of the current board with a L-shaped tromino tiles = [(center_r, center_c), (center_r, center_c + 1), (center_r + 1, center_c), (center_r + 1, center_c + 1)] # We have four quadrants (0: top-left, 1: top-right, 2: bottom-left, 3: bottom-right) for idx, (i, j) in enumerate(tiles): if idx != missing_quad: board[i][j] = 1 # Recursively fill each of the four quadrants # Top-left quadrant place_l_tiles(board, half, top_left_row, top_left_col) # Top-right quadrant place_l_tiles(board, half, top_left_row, top_left_col + half) # Bottom-left quadrant place_l_tiles(board, half, top_left_row + half, top_left_col) # Bottom-right quadrant place_l_tiles(board, half, top_left_row + half, top_left_col + half) # Initialize the board N = 4 # Example value, should be a power of 2 board = [[0 for _ in range(N)] for _ in range(N)] # Remove corners board[0][0] = -1 board[0][N-1] = -1 board[N-1][0] = -1 board[N-1][N-1] = -1 # Place L-shaped tiles starting from the top-left corner of the board place_l_tiles(board, N, 0, 0) # Print the board for row in board: print(' '.join(str(cell) for cell in row)) </syntaxhighlight>
Summary:
Please note that all contributions to Bitnami MediaWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Bitnami MediaWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width