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
0764 - Cirese
(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 isinstance(n, int) or n < 1 or n > 100: raise ValueError("Datele de intrare nu corespund restrictiilor impuse") if not isinstance(m, int) or m < 1 or m > 100: raise ValueError("Datele de intrare nu corespund restrictiilor impuse") if not isinstance(k, int) or k < 1 or k > 100: raise ValueError("Datele de intrare nu corespund restrictiilor impuse") for linie in ciresi: for val in linie: if not isinstance(val, int) or val < 0 or val > 1000: raise ValueError("Datele de intrare nu corespund restrictiilor impuse") for z in zone: if len(z) != 4 or any(not isinstance(val, int) or val < 1 or (val > n and i % 2 == 0) or (val > m and i % 2 == 1) for i, val in enumerate(z)): raise ValueError("Datele de intrare nu corespund restrictiilor impuse") 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 = map(int, input().split()) # Citim cantitatea de cireșe din fiecare sector print("Introduceți cantitatea de cireșe din fiecare sector, linie cu linie: ") ciresi = [list(map(int, input().split())) for _ in range(n)] # Citim coordonatele zonelor print("Introduceți coordonatele zonelor: ") zone = [list(map(int, input().split())) for _ in range(k)] try: validare(n, m, k, ciresi, zone) # apelul functiei de validare except ValueError as e: print(e) return # 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