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
2251 - Pereti
(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"> from collections import deque def validate_input(m, n, harta): if not (1 <= m <= 100 and 1 <= n <= 100): return False for linie in harta: for valoare in linie: if not (0 <= valoare <= 15): return False return True def rezolvare(m, n, harta): # lista cu directiile in care se poate merge directii = [(0, 1), (1, 0), (0, -1), (-1, 0)] # codurile pentru peretii dintre directiile din lista coduri = [1, 2, 4, 8] pereti = 0 for i in range(m): for j in range(n): for idx, d in enumerate(directii): # verifica daca pozitia vecina este valida if i + d[0] >= 0 and i + d[0] < m and j + d[1] >= 0 and j + d[1] < n: # verifica daca peretele face parte din perimetrul exterior if i == 0 and idx == 3 or i == m - 1 and idx == 1 or j == 0 and idx == 2 or j == n - 1 and idx == 0: continue # calculeaza codul peretelui dintre cele doua pozitii p1 = harta[i][j] p2 = harta[i + d[0]][j + d[1]] cod = coduri[idx] if p1 & cod == 0 and p2 & coduri[(idx + 2) % 4] == 0: # daca cele doua pereti sunt nevopsiti, ii vopsim pereti += 2 harta[i][j] += cod harta[i + d[0]][j + d[1]] += coduri[(idx + 2) % 4] # Afisare harta si variabile de debug for linie in harta: print(linie) print(pereti) # returneaza numarul de pereti vopsiti return pereti def main(): with open("pereti.in") as f: m, n = map(int, f.readline().split()) harta = [] for i in range(m): harta.append(list(map(int, f.readline().split()))) lungime = rezolvare(m, n, harta) with open("pereti.out", "w") as f: f.write(str(lungime) + '\n') if __name__ == "__main__": main() </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