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
0765 - Cirese1
(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> def validare(n, m, k, ciresi, zone): if not n.isdigit() or int(n) < 1 or int(n) > 1000: print("Datele de intrare nu corespund restrictiilor impuse") return False if not m.isdigit() or int(m) < 1 or int(m) > 1000: print("Datele de intrare nu corespund restrictiilor impuse") return False if not k.isdigit() or int(k) < 1 or int(k) > 10000: print("Datele de intrare nu corespund restrictiilor impuse") return False for linie in ciresi: for val in linie: if not val.isdigit() or int(val) < 0 or int(val) > 10000: print("Datele de intrare nu corespund restrictiilor impuse") return False for z in zone: if len(z) != 4 or any(not val.isdigit() or int(val) < 1 or (int(val) > int(n) and i % 2 == 0) or (int(val) > int(m) and i % 2 == 1) for i, val in enumerate(z)): print("Datele de intrare nu corespund restrictiilor impuse") return False print("Datele de intrare corespund restrictiilor impuse") return True def main(): # Solicităm introducerea numerelor n, m și k print("Introduceți numerele n, m și k, separate printr-un spațiu: ") n, m, k = input().split() # Citim cantitatea de cireșe din fiecare sector print("Introduceți cantitatea de cireșe din fiecare sector, linie cu linie: ") ciresi = [input().split() for _ in range(int(n))] # Citim coordonatele zonelor print("Introduceți coordonatele zonelor: ") zone = [input().split() for _ in range(int(k))] if not validare(n, m, k, ciresi, zone): # apelul functiei de validare return n, m, k = int(n), int(m), int(k) ciresi = [[int(val) for val in linie] for linie in ciresi] zone = [[int(val) for val in z] for z in zone] # Inițializăm o matrice de sume parțiale suma = [[0] * (m + 1) for _ in range(n + 1)] # Calculăm suma parțială pentru fiecare sector for i in range(1, n + 1): for j in range(1, m + 1): suma[i][j] = suma[i - 1][j] + suma[i][j - 1] - suma[i - 1][j - 1] + ciresi[i - 1][j - 1] max_ciresi = 0 for z in zone: # Actualizăm cantitatea maximă de cireșe dacă este cazul i1, j1, i2, j2 = z max_ciresi = max(max_ciresi, suma[i2][j2] - suma[i2][j1 - 1] - suma[i1 - 1][j2] + suma[i1 - 1][j1 - 1]) # Afișăm cantitatea maximă de cireșe pe care Gigel o poate culege print("Cantitatea maximă de cireșe pe care Gigel o poate culege este: ", max_ciresi) 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