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
2845 - Wildfire 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!
== Rezolvare == <syntaxhighlight lang="python" line="1"> # 2845 - Wildfire 1 def validate_date_intrare(x: int, y: int, n: int, m: int) -> bool: """ Verifică dacă datele de intrare sunt valide. :param x: coordonata x a copacului de la care a izbucnit focul :param y: coordonata y a copacului de la care a izbucnit focul :param n: numărul de linii ale pădurii :param m: numărul de coloane ale pădurii :return: True dacă datele sunt valide, False altfel """ if not (1 <= x <= n <= 1000 and 1 <= y <= m <= 1000): return False return True def rezolva_problema(x: int, y: int, n: int, m: int) -> list: """ Calculează numărul de zile după care va fi afectat fiecare copac al pădurii. :param x: coordonata x a copacului de la care a izbucnit focul :param y: coordonata y a copacului de la care a izbucnit focul :param n: numărul de linii ale pădurii :param m: numărul de coloane ale pădurii :return: lista cu numărul de zile pentru fiecare copac al pădurii """ matrice = [[0] * m for _ in range(n)] matrice[x][y] = 1 for val in range(2, n * m + 1): for i, linie in enumerate(matrice): for j, elem in enumerate(linie): if elem == val - 1: for ii, jj in ((i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)): if 0 <= ii < n and 0 <= jj < m and matrice[ii][jj] == 0: matrice[ii][jj] = val return [elem - 1 for linie in matrice for elem in linie] if __name__ == '__main__': try: x, y, n, m = map(int, input().strip().split()) if not validate_date_intrare(x, y, n, m): print("Datele nu corespund restricțiilor impuse.") else: rezultat = rezolva_problema(x, y, n, m) print("Datele sunt introduse corect.") for i in range(n): print(*rezultat[i * m: (i + 1) * m]) except ValueError: print("Datele introduse sunt invalide.") </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