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
3299 - Mostenire 2
(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>mostenire.in</code> 5 4 1111 1010 1111 1010 1110 <code>mostenire.out</code> 3 <syntaxhighlight lang="python" line="1"> def citire_date(nume_fisier): with open(nume_fisier, 'r') as f: N, M = map(int, f.readline().split()) matrice = [list(map(int, f.readline().split())) for _ in range(N)] return N, M, matrice def verifica_dreptunghi(matrice, x1, y1, x2, y2): # Verificam marginile dreptunghiului for i in range(x1, x2 + 1): if matrice[i][y1] != 1 or matrice[i][y2] != 1: return False for j in range(y1, y2 + 1): if matrice[x1][j] != 1 or matrice[x2][j] != 1: return False # Verificam daca exista cel putin un 0 in interior for i in range(x1 + 1, x2): for j in range(y1 + 1, y2): if matrice[i][j] == 0: return True return False def numara_padurici(N, M, matrice): numar_padurici = 0 for x1 in range(N): for y1 in range(M): for x2 in range(x1 + 1, N): for y2 in range(y1 + 1, M): if verifica_dreptunghi(matrice, x1, y1, x2, y2): numar_padurici += 1 return numar_padurici def scrie_rezultate(nume_fisier, numar_padurici): with open(nume_fisier, 'w') as f: f.write(f"{numar_padurici}\n") # Main function def main(): N, M, matrice = citire_date('date.in') numar_padurici = numara_padurici(N, M, matrice) scrie_rezultate('date.out', numar_padurici) 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