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
3394 - Mere 1
(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"> # 3394 - Mere 1 def validare(n_validare, t_validare, k_validare, zile_validare, intrebari_validare, fisier): # Verificam daca datele de intrare respecta restrictiile impuse if (n_validare < 1 or n_validare > 10000000 or t_validare < 1 or t_validare > 200000 or k_validare < 1 or k_validare > 100000): raise ValueError for zi in zile_validare: if zi[0] < 1 or zi[0] > n_validare or zi[1] < 1 or zi[1] > 1000000: raise ValueError for intrebare in intrebari_validare: if intrebare < 1 or intrebare > n_validare: raise ValueError # Daca datele de intrare sunt valide, afisam un mesaj corespunzator fisier.write("Datele de intrare corespund restrictiilor impuse\n") def mere_culese(n_culese, zile_culese, intrebari_culese, fisier): # Initializam un vector de zero-uri de lungimea numarului de prieteni plus unu mere = [0] * (n_culese + 1) # Parcurgem fiecare zi for zi in zile_culese: # Stabilim indicele prietenului care incepe culesul idx = zi[0] # Parcurgem numarul de mere culese in ziua respectiva for _ in range(zi[1]): # Adaugam un mar la prietenul cu indicele idx mere[idx] += 1 idx += 1 if idx > n_culese: idx = 1 for intrebare in intrebari_culese: fisier.write(str(mere[intrebare]) + " ") if __name__ == '__main__': fisier_intrare = open("merein.txt", "r") with open("mereout.txt", "w") as fisier_iesire: try: # Citim datele de intrare n, t, k = map(int, fisier_intrare.readline().split()) zile = [list(map(int, fisier_intrare.readline().split())) for _ in range(t)] intrebari = list(map(int, fisier_intrare.readline().split())) # Validam datele de intrare validare(n, t, k, zile, intrebari, fisier_iesire) # Rezolvam problema mere_culese(n, zile, intrebari, fisier_iesire) # Tratam eventualele erori except ValueError: fisier_iesire.write("Datele de intrare nu corespund restrictiilor impuse") except IndexError: fisier_iesire.write("Datele de intrare nu corespund restrictiilor impuse") fisier_intrare.close() </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