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
3975 - Intervale AB
(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 max_intersecting(intervals): # Sortăm intervalele după capătul drept intervals.sort(key=lambda x: x[1]) # Inițializăm o listă pentru a stoca intervalele în curs de procesare current_intervals = [] # Inițializăm numărul maxim de intervale care se intersectează max_inter = 0 for interval in intervals: # Adăugăm intervalul curent la lista de intervale în curs de procesare current_intervals.append(interval) # Eliminăm intervalele care s-au terminat while current_intervals and current_intervals[0][1] < interval[0]: current_intervals.pop(0) # Actualizăm numărul maxim de intervale care se intersectează max_inter = max(max_inter, len(current_intervals)) return max_inter def main(): # Deschidem fișierul de intrare și citim datele with open('intervalein.txt', 'r') as f: n = int(f.readline().strip()) intervals = [list(map(int, f.readline().strip().split())) for _ in range(n)] # Verificăm dacă numărul de intervale respectă restricțiile if 1 <= n <= 100000 and all(-2000000000 <= a <= b <= 2000000000 for a, b in intervals): # Dacă da, calculăm numărul maxim de intervale care se intersectează result = max_intersecting(intervals) status = "Datele de intrare corespund restrictiilor impuse." else: # Dacă nu, afișăm un mesaj de eroare result = "" status = "Datele de intrare nu corespund restrictiilor impuse." # Scriem rezultatul în fișierul de ieșire with open('intervaleout.txt', 'w') as f: f.write(status + '\n' + str(result)) 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