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
1065 - Vase 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!
= Explicație = Se introduc <code>3</code> lichide în sistemul de două vase comunicante: * primul cu volumul <code>4</code>, se introduce prin dreapta şi are culoarea <code>1</code>; * al doilea cu volumul <code>4</code>, se introduce prin stânga şi are culoarea <code>2</code>; * al treilea cu volumul <code>2</code>, se introduce prin stânga şi are culoarea <code>3</code>; Se caută gradaţiile ce corespund lichidului de culoare <code>2</code>. Gradaţia maximă la care ajunge nivelul lichidului este <code>5</code>. Lichidul de culoare <code>2</code> se aşează între gradaţiile <code>3</code> pe ramura din stânga şi <code>1</code> pe ramura din dreapta. == Încărcare soluție == === Lipește codul aici === <syntaxhighlight lang="python" line="1"> import sys nmax = 100001 class Lichid: def __init__(self, cantitate, ramura, culoare): self.cant = cantitate self.ram = ramura self.cul = culoare st = [None] * nmax dr = [None] * nmax vst = 0 vdr = 0 f = open("vase1.in", "r") g = open("vase1.out", "w") def main(): i = 0 n = 0 x = 0 z = 0 mij = 0 l1 = 0 l2 = 0 h1 = 0 h2 = 0 gasit = 0 s = 0 l1r = ' ' l2r = ' ' n = int(f.readline()) for i in range(1, n+1): line = f.readline().split() x = int(line[0]) c = line[1] s += x if c == 'S': vst += 1 st[vst] = Lichid(x, c, i) elif c == 'D': vdr += 1 dr[vdr] = Lichid(x, c, i) z = int(f.readline()) mij = s // 2 h1 = mij gasit = 0 while h1 > -mij and vst > 0 and not gasit: if st[vst].cul == z: if h1 < 0: l1 = -h1 l1r = 'D' else: l1 = h1 l1r = 'S' if h1 - st[vst].cant < 0: l2 = -(h1 - st[vst].cant) l2r = 'D' else: l2 = h1 - st[vst].cant l2r = 'S' gasit = 1 h1 -= st[vst].cant vst -= 1 h2 = mij while h2 > -mij and vdr > 0 and not gasit: if dr[vdr].cul == z: if h2 < 0: l1 = -h2 l1r = 'S' else: l1 = h2 l1r = 'D' if h2 - dr[vdr].cant < 0: l2 = -(h2 - dr[vdr].cant) l2r = 'S' else: l2 = h2 - dr[vdr].cant l2r = 'D' gasit = 1 h2 -= dr[vdr].cant vdr -= 1 if l1 == 0: l1r = l2r if l2 == 0: l2r = l1r g.write(str(mij) + "\n") if l1r == 'D' and l2r == 'S': g.write(str(l2) + " " + l2r + "\n") g.write(str(l1) + " " + l1r + "\n") elif l1r == 'S' and l2r == 'D': g.write(str(l1) + " " + l1r + "\n") g.write(str(l2) + " " + l2r + "\n") elif l1 > l2: g.write(str(l1) + " " + l1r + "\n") g.write(str(l2) + " " + l2r + "\n") else: g.write(str(l2) + " " + l2r + "\n") g.write(str(l1) + " " + l1r + "\n") f.close() g.close() 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