1# decided to add a little more Djurkane и на колите,за всеки случай някой да не остане сам на празника,
2# хубави спомени, когато в общежитието в студентски
3# град ни пъхаха брошури
4# под вратата, а ние взехме че се събрахме между 14 и 20 човека в стая на общежитие за 2ма, където са настанени 3ма,
5# всички се напиха от 9:30 до 10:30
6# 2ма паднаха по стълбите на подлеза на метрото, по път за Планета Пайнер, единият куца до края на летният семестър
7from itertools import permutations
8
9
10def organize(cars, students):
11 for car_perm in permutations(cars, len(cars)):
12 for student_perm in permutations(students, len(students)):
13 happy_students = set()
14 for student in student_perm:
15 for car in car_perm:
16 try:
17 car.add_student(student)
18 except EnvironmentError:
19 continue
20 if not student.is_comfy():
21 car.remove_student(student)
22 else:
23 happy_students.add(student)
24 if set(students) == happy_students:
25 return True
26 for car_garbage in cars:
27 for not_so_happy_student in happy_students:
28 try:
29 car_garbage.remove_student(not_so_happy_student)
30 except EnvironmentError:
31 continue
32 return False
Timed out.
| n | n | 1 | # decided to add a little more Djurkane и на колите,за всеки случай някой да не остане сам на празника, | ||
| 2 | # хубави спомени, когато в общежитието в студентски | ||||
| 3 | # град ни пъхаха брошури | ||||
| 4 | # под вратата, а ние взехме че се събрахме между 14 и 20 човека в стая на общежитие за 2ма, където са настанени 3ма, | ||||
| 5 | # всички се напиха от 9:30 до 10:30 | ||||
| 6 | # 2ма паднаха по стълбите на подлеза на метрото, по път за Планета Пайнер, единият куца до края на летният семестър | ||||
| 1 | from itertools import permutations | 7 | from itertools import permutations | ||
| 2 | 8 | ||||
| 3 | 9 | ||||
| 4 | def organize(cars, students): | 10 | def organize(cars, students): | ||
| t | t | 11 | for car_perm in permutations(cars, len(cars)): | ||
| 5 | for student_perm in permutations(students, len(students)): | 12 | for student_perm in permutations(students, len(students)): | ||
| 6 | happy_students = set() | 13 | happy_students = set() | ||
| 7 | for student in student_perm: | 14 | for student in student_perm: | ||
| 8 | for car in cars: | 15 | for car in car_perm: | ||
| 9 | try: | 16 | try: | ||
| 10 | car.add_student(student) | 17 | car.add_student(student) | ||
| 11 | except EnvironmentError: | 18 | except EnvironmentError: | ||
| 12 | continue | 19 | continue | ||
| 13 | if not student.is_comfy(): | 20 | if not student.is_comfy(): | ||
| 14 | car.remove_student(student) | 21 | car.remove_student(student) | ||
| 15 | else: | 22 | else: | ||
| 16 | happy_students.add(student) | 23 | happy_students.add(student) | ||
| 17 | if set(students) == happy_students: | 24 | if set(students) == happy_students: | ||
| 18 | return True | 25 | return True | ||
| 19 | for car_garbage in cars: | 26 | for car_garbage in cars: | ||
| 20 | for not_so_happy_stundent in happy_students: | 27 | for not_so_happy_student in happy_students: | ||
| 21 | try: | 28 | try: | ||
| 22 | car_garbage.remove_student(not_so_happy_stundent) | 29 | car_garbage.remove_student(not_so_happy_student) | ||
| 23 | except EnvironmentError: | 30 | except EnvironmentError: | ||
| 24 | continue | 31 | continue | ||
| 25 | return False | 32 | return False |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
07.12.2023 14:50