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
4052 - emigrare
(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!
==Rezolvare== <syntaxhighlight lang="python" line="1" start="1"> from collections import deque def verificare_restrictii(nr_n, nr_m): # functia de verificare a datelor de intrare if 2 <= nr_n <= 10**3 and 2 <= nr_m <= 10**3: return True else: return False def min_distance(nr_n, nr_m, matrice): dx = [-1, 0, 1, 0] dy = [0, 1, 0, -1] visited = [[False] * nr_m for _ in range(nr_n)] distanta = [[0] * nr_m for _ in range(nr_n)] q = deque() for i in range(nr_n): for j in range(nr_m): if any(matrice[i][j] != matrice[i + dx[k]][j + dy[k]] for k in range(4) if 0 <= i + dx[k] < nr_n and 0 <= j + dy[k] < nr_m): q.append((i, j)) visited[i][j] = True while q: x, y = q.popleft() for k in range(4): nx, ny = x + dx[k], y + dy[k] if 0 <= nx < nr_n and 0 <= ny < nr_m and not visited[nx][ny]: distanta[nx][ny] = distanta[x][y] + 1 q.append((nx, ny)) visited[nx][ny] = True return distanta # Rularea se face in felul urmator, se scrie de la tastatura 8, apoi 9, apoi toata matricea if __name__ == '__main__': try: n = int(input("Introduceti numarul de linii: ")) m = int(input("Introduceti numarul de coloane: ")) if verificare_restrictii(n, m): print("Datele de intrare corespund restrictiilor impuse.") matrix = [list(map(int, input().split())) for _ in range(n)] dist = min_distance(n, m, matrix) for row in dist: print(*row) else: print("Datele de intrare nu corespund restrictiilor impuse.") except ValueError: print("Datele de intrare nu corespund restrictiilor impuse.") except IndexError: print("Datele de intrare nu corespund restrictiilor impuse.") </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