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
3944 - Turn 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!
== Rezolvare == <syntaxhighlight lang="python3" line="1"> def afisare(b): non_zero_values = [value for value in b if value != 0] fout.write(" ".join(map(str, non_zero_values)) + '\n') def verif(k): if k > 1: if col[b[k]] == col[b[k-1]]: return False if lat[b[k]] > lat[b[k-1]]: return False return True def verifica_restrictii(n, h, lat, col): if not (1 <= n < 15 and 1 <= h <= 50): fout.write("Datele nu corespund restrictiilor impuse\n") return False for i in range(1, n + 1): if not (1 <= lat[i] <= 10 and 1 <= len(col[i]) <= 20 and col[i].islower()): fout.write("Datele nu corespund restrictiilor impuse\n") return False return True def bkt(k, sp): for i in range(1, n+1): if viz[i] == 0: b[k] = i viz[i] = 1 sp += lat[b[k]] if sp <= h and verif(k): if sp == h: afisare(b[:k+1]) else: bkt(k+1, sp) sp -= lat[b[k]] viz[i] = 0 if __name__ == "__main__": with open("turn_1IN.txt", 'r') as fin, open("turn_1OUT.txt", 'w') as fout: n, h = map(int, fin.readline().split()) lat = [0] * 105 b = [0] * 105 sp = 0 viz = [0] * 105 col = [""] * 105 for i in range(1, n+1): line = fin.readline().split() if len(line) < 2: fout.write("Datele nu corespund restrictiilor impuse\n") exit() lat_str, col[i] = line lat[i] = int(lat_str) if not verifica_restrictii(n, h, lat, col): exit() bkt(1, sp) </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