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
1040 - Clepsidru
(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 = * Clepsidrul este format din <code>n=2</code> clepsidre şi în incinta de sus a primei clepsidre se introduc <code>b=3</code> boabe de nisip. * Toate boabele de nisip vor ajunge în incinta de jos a ultimei clepsidre după <code>4</code> secunde. * După ce clepsidrul este aşezat <code>3</code> secunde în poziţia <code>1</code> şi <code>1</code> secundă în poziţia <code>2</code>, în clepsidre se vor găsi câte <code>(1,1)</code>, <code>(0,1)</code> boabe de nisip * <syntaxhighlight lang="python" line="1"> def experiment1(n, b): return b + (n - 1) def experiment2(n, b, k, states): # Initializare clepsidre = [0] * n clepsidre[0] = b for si, pi in states: if pi == 1: # poziția inițială for _ in range(si): for i in range(n-1, 0, -1): transfer = min(clepsidre[i-1], 1) clepsidre[i] += transfer clepsidre[i-1] -= transfer elif pi == 2: # poziția inversată for _ in range(si): for i in range(1, n): transfer = min(clepsidre[i], 1) clepsidre[i-1] += transfer clepsidre[i] -= transfer return clepsidre # Citirea input-ului n = int(input("Introduceti numarul de clepsidre: ")) b = int(input("Introduceti numarul de boabe de nisip: ")) k = int(input("Introduceti numarul de stari: ")) states = [] for _ in range(k): si = int(input("Introduceti numarul de secunde pentru starea curenta: ")) pi = int(input("Introduceti pozitia pentru starea curenta: ")) states.append((si, pi)) # Rezultatele experimentelor timp_experiment1 = experiment1(n, b) rezultat_experiment2 = experiment2(n, b, k, states) print(f"Timpul pentru experimentul 1: {timp_experiment1}") print("Numarul de boabe de nisip in fiecare clepsidra dupa experimentul 2:") for i, boabe in enumerate(rezultat_experiment2, 1): print(f"Clepsidra {i}: {boabe} boabe") </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