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
2935 - Robot 5
(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"> import sys def citeste_n(): while True: try: with open("robot5.in") as fin: c = int(fin.readline().strip()) if c >= 1 and c <= 2: print("Datele sunt corecte.") return c else: print("Datele nu sunt conform restrictiilor impuse.") except ValueError: print("Trebuie introduse doar numere intregi.") def citeste_perechi(c): valori = [] with open("robot5.in") as fin: next(fin) for i in range(1): try: line = fin.readline().strip() if not line: raise ValueError("Linia este goala.") if c == 1: N, W, X, P = map(int, line.split()) if 2 <= N <= 100000 and 1 <= W <= 1000000000 and 1 <= X <= 1000000000 and 1 <= P <= N: print("Datele sunt corecte.") valori.append((N, W, X, P)) else: print("Datele nu sunt conform restrictiilor impuse.") else: N, W, X = map(int, line.split()) if 2 <= N <= 100000 and 1 <= W <= 1000000000 and 1 <= X <= 1000000000: print("Datele sunt corecte.") valori.append((N, W, X)) else: print("Datele nu sunt conform restrictiilor impuse.") except ValueError as e: print(f"Linia {i+2}: {e}") valori.append(None) return [v for v in valori if v is not None] def robot5(valori): rezultate = [] for valoare in valori: N, W, X = valoare[:3] if len(valoare) == 4: P = valoare[3] distanta = min(N - P + 1, P) - 1 pasi = min(distanta, W // X) else: pasi = W // X rezultate.append(pasi) with open("robot5.out", "w") as fout: for rezultat in rezultate: fout.write(str(rezultat) + "\n") if len(valoare) == 3: pozitie = -1 max_pasi = 0 for i in range(1, N + 1): distanta = min(N - i + 1, i) - 1 pasi = min(distanta, W // X) if pasi > max_pasi: max_pasi = pasi pozitie = i fout.write(str(max_pasi) + " " + str(pozitie) + "\n") if _name_ == '_main_': n = citeste_n() valori = citeste_perechi(n) robot5(valori) </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