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
3745 - Oposumi
(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="python" line> def read_input(file_name): with open(file_name, 'r') as file: T, N = map(int, file.readline().strip().split()) if T == 2: K = int(file.readline().strip()) else: K = None return T, N, K def write_output(file_name, result): with open(file_name, 'w') as file: for line in result: if isinstance(line, list): file.write(' '.join(map(str, line)) + '\n') else: file.write(str(line) + '\n') def nivel_cel_mai_de_sus(N): poziții = [] valoare = 1 for i in range(N): nivel = [] for j in range(i + 1): nivel.append(valoare) valoare += 1 poziții.append(nivel) return poziții def poziția_oposumului(N, poziții, K): poziții_rezultat = [['-' for _ in range(N)] for _ in range(N)] găsit = False for i in range(N): for j in range(i + 1): if poziții[i][j] == K: poziții_rezultat[i][j] = K găsit = True break if găsit: break return poziții_rezultat def main(): input_file = 'oposumi.in' output_file = 'oposumi.out' T, N, K = read_input(input_file) if not (1 <= N <= 1000): raise ValueError("N trebuie să fie între 1 și 1000") poziții = nivel_cel_mai_de_sus(N) if T == 1: result = [] for i in range(1, N * (N + 1) // 2 + 1): găsit = False for nivel in range(N): if găsit: break for j in range(len(poziții[nivel])): if poziții[nivel][j] == i: result.append(nivel + 1) găsit = True break result = [result] # Wrap result in a list of lists elif T == 2: result = poziția_oposumului(N, poziții, K) write_output(output_file, result) 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