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
2261 - Turn
(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!
= Exemplul 1: = <code>turnIN.txt</code> 5 5 1 1 2 1 1 2 2 2 3 1 <code>turnOUT.txt</code> 2 4 1 4 2 3 5 3 1 5 4 === Explicație === Primul turn este format din cuburile: <code>2 (2,1), 4 (2,2), 1 (1,1)</code>. Al doilea turn este format din cuburile: <code>4 (2,2), 2 (2,1), 3 (1,2)</code> etc. == Exemplul 1: == <code>turnIN.txt</code> 16 5 1 1 2 1 1 2 2 2 3 1 <code>turnOUT.txt</code> Datele nu corespund restrictiilor impuse == Rezolvare == <syntaxhighlight lang="python3" line="1"> def afis(k, st, out): out.write(" ".join(map(str, st[1:k + 1])) + '\n') def vef(k, st, v): if v[st[k]]['y'] == v[st[k - 1]]['y']: return False if v[st[k]]['x'] > v[st[k - 1]]['x']: return False return True def back(k, suma, st, uz, v, h, out): for i in range(1, len(v) + 1): if not uz[i]: uz[i] = 1 st[k] = i suma += v[st[k]]['x'] if k == 1 or (vef(k, st, v) and suma <= h): if suma == h: afis(k, st, out) else: back(k + 1, suma, st, uz, v, h, out) uz[i] = 0 suma -= v[st[k]]['x'] def check_constraints(n, h, v): if not (1 <= n < 15 and 1 <= h <= 50): return False for i in range(1, n + 1): if not (1 <= v[i]['x'] <= 10 and 1 <= v[i]['y'] <= 5): return False return True def main(): with open("turnIN.txt", "r") as f_in, open("turnOUT.txt", "w") as f_out: n, h = map(int, f_in.readline().split()) v = {} for i in range(1, n + 1): line = f_in.readline().split() if len(line) < 2: f_out.write("Datele nu corespund restrictiilor impuse\n") return x, y = map(int, line) v[i] = {'x': x, 'y': y} if not check_constraints(n, h, v): f_out.write("Datele nu corespund restrictiilor impuse\n") else: st = [0] * 1010 uz = [0] * 101 back(1, 0, st, uz, v, h, f_out) 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