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
2425 - Peri
(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>peri.in</code> 4 5 1 0 0 1 0 0 1 1 0 0 0 1 0 1 0 1 1 1 0 1 <code>peri.out</code> 4 2 <syntaxhighlight lang="python" line="1"> def max_perimeter_diff(matrix): m = len(matrix) n = len(matrix[0]) max_diff = float('-inf') count_max_diff_rects = 0 # Helper function to count 1's and 0's on the perimeter def count_perimeter(x1, y1, x2, y2): ones = 0 zeros = 0 for j in range(y1, y2 + 1): if matrix[x1][j] == 1: ones += 1 else: zeros += 1 if matrix[x2][j] == 1: ones += 1 else: zeros += 1 for i in range(x1 + 1, x2): if matrix[i][y1] == 1: ones += 1 else: zeros += 1 if matrix[i][y2] == 1: ones += 1 else: zeros += 1 return ones, zeros # Iterate over all possible top-left corners (x1, y1) for x1 in range(m - 1): for y1 in range(n - 1): # Iterate over all possible bottom-right corners (x2, y2) for x2 in range(x1 + 1, m): for y2 in range(y1 + 1, n): ones, zeros = count_perimeter(x1, y1, x2, y2) diff = ones - zeros if diff > max_diff: max_diff = diff count_max_diff_rects = 1 elif diff == max_diff: count_max_diff_rects += 1 return max_diff, count_max_diff_rects # Exemplu de utilizare matrix = [ [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0] ] max_diff, count_max_diff_rects = max_perimeter_diff(matrix) print(f"Diferența maximă: {max_diff}") print(f"Numărul de dreptunghiuri: {count_max_diff_rects}") </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