回答編集履歴
10
ユーザ追加処理コード追加
test
CHANGED
@@ -121,3 +121,107 @@
|
|
121
121
|
return False
|
122
122
|
|
123
123
|
```
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
ユーザ追加処理
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
```python
|
132
|
+
|
133
|
+
import random
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
# ユーザーの情報の読み込み
|
138
|
+
|
139
|
+
users = [
|
140
|
+
|
141
|
+
(1,0,1,0),
|
142
|
+
|
143
|
+
(2,0,0,0),
|
144
|
+
|
145
|
+
(3,0,1,0),
|
146
|
+
|
147
|
+
(4,0,0,0),
|
148
|
+
|
149
|
+
(5,1,0,0),
|
150
|
+
|
151
|
+
(6,1,0,0),
|
152
|
+
|
153
|
+
(7,0,0,0),
|
154
|
+
|
155
|
+
(8,1,0,0),
|
156
|
+
|
157
|
+
(9,0,0,0),
|
158
|
+
|
159
|
+
(10,0,1,0),
|
160
|
+
|
161
|
+
(11,0,0,12),
|
162
|
+
|
163
|
+
(12,0,0,13),
|
164
|
+
|
165
|
+
(13,0,0,0),
|
166
|
+
|
167
|
+
(14,0,0,0),
|
168
|
+
|
169
|
+
(15,0,1,0),
|
170
|
+
|
171
|
+
(16,0,0,3),
|
172
|
+
|
173
|
+
(17,0,0,0),
|
174
|
+
|
175
|
+
(18,0,0,0),
|
176
|
+
|
177
|
+
(19,0,0,9),
|
178
|
+
|
179
|
+
]
|
180
|
+
|
181
|
+
no20 = (20, 0, 1, 0)
|
182
|
+
|
183
|
+
users.append(no20)
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
# ユーザーをシャッフルにし、3クラスに分ける
|
188
|
+
|
189
|
+
random.shuffle(users)
|
190
|
+
|
191
|
+
c1 = len(users) * 1 // 3
|
192
|
+
|
193
|
+
c2 = len(users) * 2 // 3
|
194
|
+
|
195
|
+
classes = class1, class2, class3 = users[:c1], users[c1:c2], users[c2:]
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
# クラス毎に、制約条件1が1人以下かつ、制約条件2が2人以下ならOK
|
200
|
+
|
201
|
+
if all(sum(u[1] for u in c) <= 1 and sum(u[2] for u in c) <= 2 for c in classes):
|
202
|
+
|
203
|
+
print('OK')
|
204
|
+
|
205
|
+
# 組み合わせNGのメンバーがクラスにいなければOK
|
206
|
+
|
207
|
+
if all(all(u[3] != m[0] for m in c) for c in classes for u in c if u[3]):
|
208
|
+
|
209
|
+
print('組み合わせもOK')
|
210
|
+
|
211
|
+
else:
|
212
|
+
|
213
|
+
print('組み合わせはNG')
|
214
|
+
|
215
|
+
else:
|
216
|
+
|
217
|
+
print('NG')
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
print(class1)
|
222
|
+
|
223
|
+
print(class2)
|
224
|
+
|
225
|
+
print(class3)
|
226
|
+
|
227
|
+
```
|
9
コメントで質問された処理の展開を追記
test
CHANGED
@@ -95,3 +95,29 @@
|
|
95
95
|
print(class3)
|
96
96
|
|
97
97
|
```
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
コメントで質問された処理を展開:
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
```python
|
106
|
+
|
107
|
+
def conflict(classes):
|
108
|
+
|
109
|
+
for class_ in classes:
|
110
|
+
|
111
|
+
for user in class_:
|
112
|
+
|
113
|
+
if user[3] != 0:
|
114
|
+
|
115
|
+
for member in class_:
|
116
|
+
|
117
|
+
if user[3] == member[0]
|
118
|
+
|
119
|
+
return True
|
120
|
+
|
121
|
+
return False
|
122
|
+
|
123
|
+
```
|
8
コメント修正
test
CHANGED
@@ -54,7 +54,7 @@
|
|
54
54
|
|
55
55
|
|
56
56
|
|
57
|
-
# ユーザーをシャッフルにし、3
|
57
|
+
# ユーザーをシャッフルにし、3クラスに分ける
|
58
58
|
|
59
59
|
random.shuffle(users)
|
60
60
|
|
7
ユーザ情報をタプルに変更
test
CHANGED
@@ -12,43 +12,43 @@
|
|
12
12
|
|
13
13
|
users = [
|
14
14
|
|
15
|
-
|
15
|
+
(1,0,1,0),
|
16
16
|
|
17
|
-
|
17
|
+
(2,0,0,0),
|
18
18
|
|
19
|
-
|
19
|
+
(3,0,1,0),
|
20
20
|
|
21
|
-
|
21
|
+
(4,0,0,0),
|
22
22
|
|
23
|
-
|
23
|
+
(5,1,0,0),
|
24
24
|
|
25
|
-
|
25
|
+
(6,1,0,0),
|
26
26
|
|
27
|
-
|
27
|
+
(7,0,0,0),
|
28
28
|
|
29
|
-
|
29
|
+
(8,1,0,0),
|
30
30
|
|
31
|
-
|
31
|
+
(9,0,0,0),
|
32
32
|
|
33
|
-
|
33
|
+
(10,0,1,0),
|
34
34
|
|
35
|
-
|
35
|
+
(11,0,0,12),
|
36
36
|
|
37
|
-
|
37
|
+
(12,0,0,13),
|
38
38
|
|
39
|
-
|
39
|
+
(13,0,0,0),
|
40
40
|
|
41
|
-
|
41
|
+
(14,0,0,0),
|
42
42
|
|
43
|
-
|
43
|
+
(15,0,1,0),
|
44
44
|
|
45
|
-
|
45
|
+
(16,0,0,3),
|
46
46
|
|
47
|
-
|
47
|
+
(17,0,0,0),
|
48
48
|
|
49
|
-
|
49
|
+
(18,0,0,0),
|
50
50
|
|
51
|
-
|
51
|
+
(19,0,0,9),
|
52
52
|
|
53
53
|
]
|
54
54
|
|
6
c1,c2計算方法変更
test
CHANGED
@@ -58,9 +58,9 @@
|
|
58
58
|
|
59
59
|
random.shuffle(users)
|
60
60
|
|
61
|
-
c1 = len(users) // 3
|
61
|
+
c1 = len(users) * 1 // 3
|
62
62
|
|
63
|
-
c2 =
|
63
|
+
c2 = len(users) * 2 // 3
|
64
64
|
|
65
65
|
classes = class1, class2, class3 = users[:c1], users[c1:c2], users[c2:]
|
66
66
|
|
5
コメント修正
test
CHANGED
@@ -54,7 +54,7 @@
|
|
54
54
|
|
55
55
|
|
56
56
|
|
57
|
-
# ユーザー
|
57
|
+
# ユーザーをシャッフルにし、3組に分ける
|
58
58
|
|
59
59
|
random.shuffle(users)
|
60
60
|
|
@@ -66,15 +66,17 @@
|
|
66
66
|
|
67
67
|
|
68
68
|
|
69
|
-
#
|
69
|
+
# クラス毎に、制約条件1が1人以下かつ、制約条件2が2人以下ならOK
|
70
70
|
|
71
71
|
if all(sum(u[1] for u in c) <= 1 and sum(u[2] for u in c) <= 2 for c in classes):
|
72
72
|
|
73
73
|
print('OK')
|
74
74
|
|
75
|
-
|
75
|
+
# 組み合わせNGのメンバーがクラスにいなければOK
|
76
76
|
|
77
|
+
if all(all(u[3] != m[0] for m in c) for c in classes for u in c if u[3]):
|
78
|
+
|
77
|
-
print('組み合わせ
|
79
|
+
print('組み合わせもOK')
|
78
80
|
|
79
81
|
else:
|
80
82
|
|
4
ユーザ情報の先頭要素を1からの出席番号に変更、最後の要素も出席番号
test
CHANGED
@@ -12,27 +12,25 @@
|
|
12
12
|
|
13
13
|
users = [
|
14
14
|
|
15
|
-
[
|
15
|
+
[1,0,1,0],
|
16
16
|
|
17
|
-
[
|
17
|
+
[2,0,0,0],
|
18
18
|
|
19
|
-
[
|
19
|
+
[3,0,1,0],
|
20
20
|
|
21
|
-
[
|
21
|
+
[4,0,0,0],
|
22
|
-
|
23
|
-
[4,1,0,0],
|
24
22
|
|
25
23
|
[5,1,0,0],
|
26
24
|
|
27
|
-
[6,
|
25
|
+
[6,1,0,0],
|
28
26
|
|
29
|
-
[7,
|
27
|
+
[7,0,0,0],
|
30
28
|
|
31
|
-
[8,
|
29
|
+
[8,1,0,0],
|
32
30
|
|
33
|
-
[9,0,
|
31
|
+
[9,0,0,0],
|
34
32
|
|
35
|
-
[10,0,
|
33
|
+
[10,0,1,0],
|
36
34
|
|
37
35
|
[11,0,0,12],
|
38
36
|
|
@@ -40,15 +38,17 @@
|
|
40
38
|
|
41
39
|
[13,0,0,0],
|
42
40
|
|
43
|
-
[14,0,
|
41
|
+
[14,0,0,0],
|
44
42
|
|
45
|
-
[15,0,0
|
43
|
+
[15,0,1,0],
|
46
44
|
|
47
|
-
[16,0,0,
|
45
|
+
[16,0,0,3],
|
48
46
|
|
49
47
|
[17,0,0,0],
|
50
48
|
|
51
|
-
[18,0,0,
|
49
|
+
[18,0,0,0],
|
50
|
+
|
51
|
+
[19,0,0,9],
|
52
52
|
|
53
53
|
]
|
54
54
|
|
3
組み合わせ対応
test
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
こんな書き方はいかが?
|
2
|
-
|
3
|
-
組み合わせNGが抜けてたのでのちほど修正します。
|
4
2
|
|
5
3
|
|
6
4
|
|
@@ -36,9 +34,9 @@
|
|
36
34
|
|
37
35
|
[10,0,0,0],
|
38
36
|
|
39
|
-
[11,0,0,1
|
37
|
+
[11,0,0,12],
|
40
38
|
|
41
|
-
[12,0,0,1
|
39
|
+
[12,0,0,13],
|
42
40
|
|
43
41
|
[13,0,0,0],
|
44
42
|
|
@@ -74,6 +72,14 @@
|
|
74
72
|
|
75
73
|
print('OK')
|
76
74
|
|
75
|
+
if all(all(a[3] != b[0] for b in c) for c in classes for a in c if a[3]):
|
76
|
+
|
77
|
+
print('組み合わせはOK')
|
78
|
+
|
79
|
+
else:
|
80
|
+
|
81
|
+
print('組み合わせはNG')
|
82
|
+
|
77
83
|
else:
|
78
84
|
|
79
85
|
print('NG')
|
2
修正中
test
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
こんな書き方はいかが?
|
2
|
+
|
3
|
+
組み合わせNGが抜けてたのでのちほど修正します。
|
2
4
|
|
3
5
|
|
4
6
|
|
1
バグ修正
test
CHANGED
@@ -68,7 +68,7 @@
|
|
68
68
|
|
69
69
|
# 各組に入っている人の内訳が、制約条件1が1人以下かつ、制約条件2が2人以下のとき、
|
70
70
|
|
71
|
-
if all(sum(u[1] for u in c) <= 1
|
71
|
+
if all(sum(u[1] for u in c) <= 1 and sum(u[2] for u in c) <= 2 for c in classes):
|
72
72
|
|
73
73
|
print('OK')
|
74
74
|
|