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
2729 - SAO
(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"> def citeste_n(): while True: try: n = int(input("Introduceti numarul de monștri: ")) if n >= 1 and n <= 10000: print("Datele sunt corecte.") return n else: print("Datele nu sunt conform restrictiilor impuse.") except ValueError: print("Trebuie introduse doar numere intregi.") def citeste_monstri(n): monstri = [] for i in range(n): while True: try: rezistenta, putere = map(int, input( "Introduceti rezistența și puterea monștrilor separate prin spatiu: ").split()) if 1 <= rezistenta <= 2 * 63 and 1 <= putere <= 2 * 63: print("Datele sunt corecte.") monstri.append((rezistenta, putere)) break else: print("Datele nu sunt conform restrictiilor impuse.") except ValueError: print("Trebuie introduse doar valori numerice.") return monstri def citeste_m(): while True: try: m = int(input("Introduceti numarul de oferte: ")) if m >= 1 and m <= 10000: print("Datele sunt corecte.") return m else: print("Datele nu sunt conform restrictiilor impuse.") except ValueError: print("Trebuie introduse doar numere intregi.") def citeste_oferte(m): oferte = [] for i in range(m): while True: try: rezistenta_armura, putere_sabie, pret = map(int, input( "Introduceti rezistența armurii, puterea săbiei și prețul separate prin spatiu: ").split()) if 1 <= rezistenta_armura <= 2 * 63 and 1 <= putere_sabie <= 2 * 63 and 1 <= pret <= 2 ** 63: print("Datele sunt corecte.") oferte.append((rezistenta_armura, putere_sabie, pret)) break else: print("Datele nu sunt conform restrictiilor impuse.") except ValueError: print("Trebuie introduse doar valori numerice.") return oferte def Sao(monstri, oferte): # Sortam ofertele in ordine crescatoare dupa pret oferte = sorted(oferte, key=lambda x: x[2]) # Pentru fiecare montru, cautam cea mai ieftina oferta care il poate invinge cost_minim = 0 for i in range(len(monstri)): rez_monstru, putere_monstru = monstri[i] oferta_potrivita = False for j in range(len(oferte)): rez_armura, putere_sabie, pret = oferte[j] if rez_armura >= putere_monstru and putere_sabie >= rez_monstru: cost_minim += pret oferta_potrivita = True break if not oferta_potrivita: print(-1) return print(cost_minim) if _name_ == '_main_': n = citeste_n() numere = citeste_monstri(n) m = citeste_m() numere2 = citeste_oferte(m) Sao(numere,numere2) </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