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
1677 - Tort
(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"> #1677 - Tort def read_input(file_name): try: with open(file_name, 'r') as file: N, M = map(int, file.readline().split()) tort = [list(map(int, line.strip())) for line in file] if 1 <= N <= 500 and 1 <= M <= 500: return N, M, tort else: raise ValueError("Numerele nu respecta restricțiile.") except Exception as e: print(f"Nu au fost respectate cerintele impuse: {str(e)}") return None def write_output(file_name, result): with open(file_name, 'w') as file: if result is not None: for item in result: file.write(" ".join(map(str, item)) + "\n") def find_largest_square(N, M, tort, i, j): size = 1 while i + size <= N and j + size <= M: if all(tort[x][y] == tort[i][j] for x in range(i, i + size) for y in range(j, j + size)): size += 1 else: break #1677 - Tort return size - 1 # Return the side length of the largest square def find_felii(N, M, tort): felii = [] for i in range(N): for j in range(M): side_length = find_largest_square(N, M, tort, i, j) if side_length > 0: felii.append((side_length, i + side_length, j + side_length)) felii.sort(key=lambda x: (x[0], x[1], x[2])) return felii def main(input_file, output_file): result = read_input(input_file) if result is not None: N, M, tort = result felii = find_felii(N, M, tort) write_output(output_file, felii) if __name__ == "__main__": main("tortin.txt", "tortout.txt") </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