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
3065 - trio
(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 reverse_piece(piece): """Returnează piesa inversată.""" return piece[::-1] def are_friends(piece1, piece2): """Verifică dacă două piese sunt prietene.""" if piece1 == piece2: return True if piece1 == reverse_piece(piece2): return True c1, c2, c3 = piece1 for i in range(3): if piece2 == c2 + c3 + c1 or piece2 == c3 + c1 + c2: return True c1, c2, c3 = c3, c1, c2 # permutăm cifrele return False def cerinta1(pieces): """Determină M al pieselor identice cu cea selectată.""" from collections import Counter counter = Counter(pieces) most_common_piece, count = counter.most_common(1)[0] return count def cerinta2(pieces): """Numărul grupurilor de piese prietene.""" n = len(pieces) visited = [False] * n def dfs(i): stack = [i] while stack: node = stack.pop() if not visited[node]: visited[node] = True for j in range(n): if not visited[j] and are_friends(pieces[node], pieces[j]): stack.append(j) groups = 0 for i in range(n): if not visited[i]: groups += 1 dfs(i) return groups def cerinta3(pieces): """Numărul maxim de piese dintr-o secvență ce conține piese prietene.""" n = len(pieces) max_length = 0 current_length = 0 for i in range(n): if i == 0 or are_friends(pieces[i], pieces[i - 1]): current_length += 1 else: max_length = max(max_length, current_length) current_length = 1 max_length = max(max_length, current_length) return max_length def main(): with open('trio.in', 'r') as f: data = f.read().splitlines() c = int(data[0].strip()) n = int(data[1].strip()) pieces = [line.strip().replace(" ", "") for line in data[2:2 + n]] assert 2 <= n <= 100000, "N trebuie să fie între 2 și 100000" assert all(len(piece) == 3 for piece in pieces), "Fiecare piesă trebuie să aibă exact 3 cifre" if c == 1: result = cerinta1(pieces) elif c == 2: result = cerinta2(pieces) elif c == 3: result = cerinta3(pieces) else: raise ValueError("C trebuie să fie 1, 2 sau 3") with open('trio.out', 'w') as f: f.write(f"{result}\n") 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