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
3382 - robot2
(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="1"> # 3382 - robot2 from typing import Tuple, List def validare_date(cerinta: int, nr_bomboane: int, dimensiuni_bomboane: List[Tuple[int, int]]) -> bool: """ Verifică dacă datele de intrare corespund constrângerilor problemei. Returnează True dacă datele sunt valide și False altfel. """ if not (1 <= cerinta <= 2): return False if not (2 <= nr_bomboane <= 500000): return False for x, y in dimensiuni_bomboane: if not (0 < x < 100 and 0 < y < 100): return False return True def rezolvare_problema(cerinta: int, nr_bomboane: int, dimensiuni_bomboane: List[Tuple[int, int]]) -> int: """ Rezolvă problema pe baza datelor de intrare și returnează răspunsul. """ bomboane_distincte = [0] * 10002 for x, y in dimensiuni_bomboane: bomboane_distincte[min(x, y) * 100 + max(x, y)] += 1 if cerinta == 1: nr_bomboane_distincte = sum(1 for i in range(100, 10002) if bomboane_distincte[i] != 0) return nr_bomboane_distincte else: nr_maxim_cutii = float('inf') for i in range(1, 10002): if bomboane_distincte[i] != 0 and bomboane_distincte[i] < nr_maxim_cutii: nr_maxim_cutii = bomboane_distincte[i] return nr_maxim_cutii if __name__ == '__main__': with open('robot.in', 'r') as f_in, open('robot.out', 'w') as f_out: cerinta = int(f_in.readline().strip()) nr_bomboane = int(f_in.readline().strip()) dimensiuni_bomboane = [tuple(map(int, line.strip().split())) for line in f_in.readlines()] if not validare_date(cerinta, nr_bomboane, dimensiuni_bomboane): print('Datele nu corespund restrictiilor impuse.') f_out.write('Datele nu corespund restrictiilor impuse.') else: print('Datele sunt introduse corect.') raspuns = rezolvare_problema(cerinta, nr_bomboane, dimensiuni_bomboane) f_out.write(str(raspuns)) </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