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
4128 - Iluminat
(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!
=== Explicație === Cerința este <code>1</code>. Se sting becurile din cartierul având <code>16</code> stâlpi de iluminat, ceea ce duce la stingerea becurilor de pe stâlpii din linia <code>2</code> și din coloana <code>1</code>. Tabloul devine: <code>0 2 3 4</code> <code>0 0 0 0</code> <code>0 9 7 14</code> <code>0 11 8 15</code> La etapa a doua, primul cartier în care se sting becurile are <code>15</code> stâlpi de iluminat. <syntaxhighlight lang="python" line="1"> import numpy as np def generate_matrix(n): return np.arange(1, n*n + 1).reshape(n, n) def find_max_and_sting(matrix): max_value = np.max(matrix) max_index = np.unravel_index(np.argmax(matrix, axis=None), matrix.shape) row, col = max_index matrix[row, :] = 0 matrix[:, col] = 0 return max_value, np.count_nonzero(matrix == 0) def max_bulbs_in_kxk(matrix, k): max_sum = 0 for i in range(matrix.shape[0] - k + 1): for j in range(matrix.shape[1] - k + 1): submatrix_sum = np.sum(matrix[i:i+k, j:j+k]) if submatrix_sum > max_sum: max_sum = submatrix_sum return max_sum def stage_results(n, k): matrix = generate_matrix(n) original_matrix = matrix.copy() max_value_at_k = 0 total_sting_at_k = 0 for stage in range(1, k + 1): max_value, sting_count = find_max_and_sting(matrix) if stage == k: max_value_at_k = max_value total_sting_at_k = sting_count max_in_kxk_before_sting = max_bulbs_in_kxk(original_matrix, k) return max_value_at_k, total_sting_at_k, max_in_kxk_before_sting # Citirea datelor de intrare n = int(input()) k = int(input()) # Calcularea și afișarea rezultatelor max_value_at_k, total_sting_at_k, max_in_kxk_before_sting = stage_results(n, k) print(max_value_at_k) print(total_sting_at_k) print(max_in_kxk_before_sting) </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