File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
puzzles/python3/super-computer Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -54,3 +54,23 @@ To solve this problem, you need to find the maximum number of non-overlapping ca
54545 . Output the count of performed calculations as the maximum number of calculations that can be carried out without overlapping.
5555
5656This algorithm ensures that calculations are scheduled in a way that maximizes the usage of the supercomputer without overlapping reservation periods.
57+
58+ ## Example Code
59+
60+ ``` python
61+ # Sort the calculations
62+ calculations.sort(key = lambda x : x[1 ])
63+
64+ # Initialize variables
65+ max_calculations = 0
66+ selected_calculations = []
67+
68+ # Greedy algorithm
69+ for calculation in calculations:
70+ if not selected_calculations:
71+ selected_calculations.append(calculation)
72+ max_calculations += 1
73+ elif calculation[0 ] > selected_calculations[- 1 ][1 ]:
74+ selected_calculations.append(calculation)
75+ max_calculations += 1
76+ ```
You can’t perform that action at this time.
0 commit comments