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
1204 - Trenuri
(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> #1204 - Trenuri def trenuri(N, M, trenuri, pasageri): # Verificare restricții if not (1 <= N <= 100000 and 1 <= M <= 100000): return "Fals" for i in range(N): if not (1 <= trenuri[i][0] <= trenuri[i][1] <= 1000000000): return "Fals" for i in range(M): if not (1 <= pasageri[i][0] <= pasageri[i][1] <= 1000000000): return "Fals" # Sortăm pasagerii în ordinea crescătoare a stației de sosire pasageri = sorted(pasageri, key=lambda x: x[1]) # Sortăm trenurile în ordinea crescătoare a stației de sosire trenuri = sorted(enumerate(trenuri), key=lambda x: x[1][0]) result = [0] * M # Configurația trenurilor pentru fiecare pasager total_pasageri = 0 # Numărul total de pasageri for pasager in pasageri: start, end = pasager # Găsim primul tren disponibil în intervalul dorit for i, (statie, capacitate) in trenuri: if statie <= start and start <= end <= capacitate: result[pasager[2]] = i + 1 # Salvăm indexul trenului pentru pasager total_pasageri += 1 break return total_pasageri, result # Citirea datelor de intrare din fișierul "trenuriin.txt" try: with open("trenuriin.txt", "r") as file: N, M = map(int, file.readline().split()) trenuri = [tuple(map(int, file.readline().split())) for _ in range(N)] pasageri = [tuple(map(int, file.readline().split())) + (i,) for i in range(M)] except Exception as e: print("Fals") exit() # Calcularea numărului maxim de pasageri și a configurației trenurilor result = trenuri(N, M, trenuri, pasageri) if result == "Fals": print(result) else: # Scrierea rezultatului în fișierul "trenuriout.txt" with open("trenuriout.txt", "w") as file: file.write(str(result[0]) + "\n") for tren in result[1]: file.write(str(tren) + "\n") </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