Предизвикателства > Осмодекемврийско пътуване > Решения > Решението на Атанас Христов

Резултати
1 точки от тестове
1 точки от учител

2 точки общо

5 успешни теста
0 неуспешни теста
Код

 1def rec_func(cars, students, students_comfort):    
 2    for student in students:
 3        if student.is_comfy() != None and not student.is_comfy():
 4            return False
 5        if student.is_comfy() == None:
 6            for car in students_comfort[student]:
 7                try:
 8                    car.add_student(student)
 9                    if rec_func(cars, students, students_comfort):
10                        return True
11                    car.remove_student(student)
12                except EnvironmentError:
13                    continue
14    return all(student.is_comfy() for student in students)
15
16
17def organize(cars, students):
18    if len(cars) * 4 < len(students):
19        return False
20    students_comfort = {student : [] for student in students}
21    for student in students:
22        for car in cars:
23            car.add_student(student)
24            if student.is_comfy():
25                students_comfort[student].append(car)
26            car.remove_student(student)
27    for student in students_comfort:
28        car_list = students_comfort[student]
29        if len(car_list) == 0:
30            return False
31        if len(car_list) == 1:
32            try:
33                car_list[0].add_student(student)
34            except EnvironmentError:
35                return False
36    return rec_func(cars, students, students_comfort) # name is shit, I know :^)

.....
----------------------------------------------------------------------
Ran 5 tests in 0.001s

OK

Дискусия
История
Това решение има само една версия.