質問編集履歴

1

numpy を使用するようにしました。/再帰関数を使用するようにしました。

2020/09/13 04:14

投稿

kei.a
kei.a

スコア1

test CHANGED
File without changes
test CHANGED
@@ -24,89 +24,65 @@
24
24
 
25
25
  ```Python
26
26
 
27
- import sys
27
+ import numpy as np
28
28
 
29
- import numpy as np
29
+
30
30
 
31
31
  def camp(y, x):
32
32
 
33
33
  if table[y-1][x] == '.':
34
34
 
35
- check.append([y-1, x])
35
+ table[y-1][x] = '*'
36
36
 
37
- table[y-1][x] = '*'
37
+ camp(y-1, x)
38
38
 
39
39
  if table[y+1][x] == '.':
40
40
 
41
41
  table[y+1][x] = '*'
42
42
 
43
- check.append([y+1, x])
43
+ camp(y+1, x)
44
44
 
45
45
  if table[y][x-1] == '.':
46
46
 
47
- check.append([y, x-1])
47
+ table[y][x-1] = '*'
48
48
 
49
- table[y][x-1] = '*'
49
+ camp(y, x-1)
50
50
 
51
51
  if table[y][x+1] == '.':
52
52
 
53
- check.append([y, x+1])
54
-
55
53
  table[y][x+1] = '*'
56
54
 
57
- return None
55
+ camp(y, x+1)
58
56
 
59
-
57
+ return
58
+
59
+
60
60
 
61
61
  H, W = list(map(int, input().split(' ')))
62
62
 
63
- table = []
63
+ table = np.full([H + 2, W + 2], '#')
64
64
 
65
- check = []
66
65
 
67
- ciling = []
68
-
69
- for i in range(W+2):
70
-
71
- ciling.append('#')
72
-
73
- table.append(ciling)
74
66
 
75
67
  for y in range(H):
76
68
 
77
69
  l = input()
78
70
 
79
- line = ['#']
80
-
81
71
  for x in range(W):
82
72
 
83
- line.append(l[x])
84
-
85
- if l[x] == '*':
86
-
87
- check.append([y+1, x+1])
88
-
89
- line.append('#')
90
-
91
- table.append(line)
92
-
93
- table.append(ciling)
73
+ table[y+1][x+1] = l[x]
94
74
 
95
75
 
96
76
 
97
- while check:
77
+ target = np.where(table == '*')
98
78
 
99
- for y ,x in check:
100
-
101
- check.pop()
102
-
103
- camp(y, x)
79
+ camp(target[0][0], target[1][0])
104
80
 
105
81
 
106
82
 
107
- for y in range(1,H+1):
83
+ for y in range(1, H+1):
108
84
 
109
- for x in range(1,W+1):
85
+ for x in range(1, W+1):
110
86
 
111
87
  print(table[y][x],end='')
112
88