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
2970 - Paralele1
(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> #2970 paralele1 def count_parallel_segments_on_rows(matrix): count = 0 for row in matrix: segment_started = False ones_count = 0 for cell in row: if cell == 1: ones_count += 1 if not segment_started: segment_started = True count += 1 else: segment_started = False if ones_count > 1: count += ones_count - 1 ones_count = 0 return count def count_parallel_segments_on_columns(matrix): count = 0 for col in range(len(matrix[0])): segment_started = False ones_count = 0 for row in range(len(matrix)): if matrix[row][col] == 1: ones_count += 1 if not segment_started: segment_started = True count += 1 else: segment_started = False if ones_count > 1: count += ones_count - 1 ones_count = 0 return count def read_input(file_path): with open(file_path, 'r') as fin: T, N, M = map(int, fin.readline().split()) matrix = [list(map(int, fin.readline().split())) for _ in range(N)] if not validate_input(T, N, M, matrix): print("Date de intrare invalide.") exit() return T, matrix def write_output(file_path, count): with open(file_path, 'w') as fout: fout.write(str(count)) def validate_input(T, N, M, matrix): if T not in {1, 2}: return False if not (2 <= N <= 500): return False if not (2 <= M <= 500): return False if len(matrix) != N: return False for row in matrix: if len(row) != M: return False for cell in row: if cell not in {0, 1}: return False return True def main(): file_in = "paralele.in" file_out = "paralele.out" T, matrix = read_input(file_in) count = 0 if T == 1: count = count_parallel_segments_on_rows(matrix) elif T == 2: count = count_parallel_segments_on_columns(matrix) write_output(file_out, count) 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