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
1162 - Rox
(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> #1162 Rox def validate_input(N, M, data, questions): for L1, C1, L2, C2, T in data: if not (1 <= L1 <= L2 <= N and 1 <= C1 <= C2 <= M): return False if not ('A' <= T <= 'Z'): return False for L, C in questions: if not (1 <= L <= N and 1 <= C <= M): return False return True def read_input(file_path): with open(file_path, 'r') as file: N, M, U = map(int, file.readline().split()) data = [] for _ in range(U): L1, C1, L2, C2, T = file.readline().split() data.append((int(L1), int(C1), int(L2), int(C2), T)) Q = int(file.readline()) questions = [tuple(map(int, file.readline().split())) for _ in range(Q)] return N, M, data, questions def count_remaining_flowers(N, M, data, questions): board = {} for L1, C1, L2, C2, T in data: for i in range(L1, L2 + 1): for j in range(C1, C2 + 1): if (i, j) not in board: board[(i, j)] = {} if T in board[(i, j)]: board[(i, j)][T] += 1 else: board[(i, j)][T] = 1 results = [] for L, C in questions: remaining_flowers = 0 if (L, C) in board: for flower_count in board[(L, C)].values(): if flower_count % 2 == 1: remaining_flowers += 1 results.append(remaining_flowers) return results def write_output(file_path, results): with open(file_path, 'w') as file: for result in results: file.write(str(result) + '\n') def main(): input_file = "rox.in" output_file = "rox.out" # Citire date de intrare N, M, data, questions = read_input(input_file) # Validare date de intrare if not validate_input(N, M, data, questions): print("Date de intrare invalide!") return # Calculare numar de flori ramase pentru fiecare intrebare results = count_remaining_flowers(N, M, data, questions) # Scriere rezultate write_output(output_file, results) 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