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
3087 - Lego
(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!
== Explicație = Se rezolvă doar cerința 1. Pe semnal este scris numărul 153. Fiecare copil are 3 piese cu cifra 4 și o piesă cu cifra 7. Crina nu poate construi cu aceste piese un număr mai mic decât 153, de aceea autocarul său este identificat cu numărul 0. Rareș construiește numărul N2 = 4447. <br> == Exemplul 2 == ; lego.in 2 42 1 3 1 5 ; lego.out 7 == Explicație == Se rezolvă doar cerința 2. Pe semnal este scris numărul 42. Fiecare copil are o cifră de 3 și o cifră de 5. Crina construiește numărul N1 = 35 și așteaptă la semnal 42 - 35 = 7 minute. Rareș construiește numărul N2 = 53 și așteaptă la semnal 53 - 42 = 11 minute. Numărul minim al minutelor de așteptare este 7. <br> == Rezolvare == <syntaxhighlight lang="python" line> def build_number(pieces): number = 0 for i, piece in enumerate(pieces): number += piece * 10 ** i return number def main(): with open("lego.in", "r") as fin: c = int(fin.readline()) s = int(fin.readline()) pieces = [list(map(int, fin.readline().split())) for _ in range(2)] if c == 1: n1_pieces = [min(pieces[0][i], s) for i in range(10)] n2_pieces = [min(pieces[1][i], s) for i in range(10)] n1 = build_number(n1_pieces) n2 = build_number(n2_pieces) print(n1, n2) elif c == 2: min_wait = float('inf') for i in range(1, s): n1_pieces = [min(pieces[0][j], i) for j in range(10)] n2_pieces = [min(pieces[1][j], s - i) for j in range(10)] n1 = build_number(n1_pieces) n2 = build_number(n2_pieces) wait = abs(s - n1) + abs(s - n2) min_wait = min(min_wait, wait) print(min_wait) 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