1from itertools import permutations
2
3def organize(cars, students):
4 if len(cars) < 4 * len(students):
5 return False
6 seats = []
7 for num in range(0, len(cars)):
8 for _ in range(1,5):
9 seats.append(num)
10 for order in permutations(seats, len(students)):
11 index = 0
12 for num in order:
13 cars[num].add_student(students[index])
14 index += 1
15 for student in students:
16 if student.is_comfy() is False:
17 break
18 else:
19 return True
20 index = 0
21 for num in order:
22 cars[num].remove_student(students[index])
23 index += 1
24 return False
F..FF
======================================================================
FAIL: test_big_input (test.TesFull)
Test a big case to ensure no huge bruteforcing.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 90, in test_big_input
anti_rusalov_true(self, organize(cars, students))
AssertionError: False is not true
======================================================================
FAIL: test_regular_case (test.TesFull)
Test a regular case.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 47, in test_regular_case
anti_rusalov_true(self, organize(cars, students))
AssertionError: False is not true
======================================================================
FAIL: test_single_solution_case (test.TesFull)
Test a single-solution case.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 65, in test_single_solution_case
anti_rusalov_true(self, organize(cars, students))
AssertionError: False is not true
----------------------------------------------------------------------
Ran 5 tests in 0.001s
FAILED (failures=3)
f | 1 | from itertools import permutations | f | 1 | from itertools import permutations |
2 | 2 | ||||
3 | def organize(cars, students): | 3 | def organize(cars, students): | ||
4 | if len(cars) < 4 * len(students): | 4 | if len(cars) < 4 * len(students): | ||
5 | return False | 5 | return False | ||
n | 6 | n | |||
7 | seats = [] | 6 | seats = [] | ||
8 | for num in range(0, len(cars)): | 7 | for num in range(0, len(cars)): | ||
9 | for _ in range(1,5): | 8 | for _ in range(1,5): | ||
10 | seats.append(num) | 9 | seats.append(num) | ||
n | 11 | n | |||
12 | for order in permutations(seats, len(students)): | 10 | for order in permutations(seats, len(students)): | ||
13 | index = 0 | 11 | index = 0 | ||
14 | for num in order: | 12 | for num in order: | ||
15 | cars[num].add_student(students[index]) | 13 | cars[num].add_student(students[index]) | ||
16 | index += 1 | 14 | index += 1 | ||
n | 17 | n | |||
18 | for student in students: | 15 | for student in students: | ||
19 | if student.is_comfy() is False: | 16 | if student.is_comfy() is False: | ||
20 | break | 17 | break | ||
21 | else: | 18 | else: | ||
22 | return True | 19 | return True | ||
n | 23 | n | |||
24 | index = 0 | 20 | index = 0 | ||
25 | for num in order: | 21 | for num in order: | ||
26 | cars[num].remove_student(students[index]) | 22 | cars[num].remove_student(students[index]) | ||
t | 27 | index += 1 | t | 23 | index += 1 |
28 | |||||
29 | return False | 24 | return False | ||
30 | 25 | ||||
31 | 26 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|