-
Notifications
You must be signed in to change notification settings - Fork 0
/
FashionPolice-random.py
50 lines (38 loc) · 1.16 KB
/
FashionPolice-random.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import random
T = int(input())
def valid(outfit, solution):
if outfit in solution:
return False
K1 = 0
K2 = 0
K3 = 0
for sol in solution:
if outfit[0] == sol[0] and outfit[1] == sol[1]:
K1 += 1
if outfit[0] == sol[0] and outfit[2] == sol[2]:
K2 += 1
if outfit[1] == sol[1] and outfit[2] == sol[2]:
K3 += 1
if K1 >= K or K2 >= K or K3 >= K:
return False
return True
for i in range(1, T + 1):
[J, P, S, K] = [int(i) for i in input().split()]
max_possible = J*P*min(K, S)
print("Case #{}: {}".format(i, max_possible))
outfits = []
for ji in range(J):
for pi in range(P):
for si in range(S):
outfits.append([ji+1, pi+1, si+1])
solution = []
while len(solution) < max_possible:
solution = []
random.shuffle(outfits)
for outfit in outfits:
if valid(outfit, solution):
solution.append(outfit)
if len(solution) == max_possible:
break
for combo in solution:
print("{} {} {}".format(combo[0], combo[1], combo[2]))