Python初心者です。
ARC031B(https://atcoder.jp/contests/arc031/tasks/arc031_2)
について、コードを途中まで書いてみたのですが、inputしたAの中身が保持されず困っています。
def dfs(x,y): dx = [0,0,1,-1] dy = [-1,1,0,0] field[x][y]="1" for i in range(4): nx = x + dx[i] ny = y + dy[i] if nx>=0 and nx<10 and ny>=0 and ny<10 and field[nx][ny]=="o": dfs(nx,ny) A = [list(input())for i in range(10)] for i in range(10): for j in range(10): field = A dfs(i,j) print(A) print(field)
__________________________________
input
xxxxxxxxxx
xoooooooxx
xxoooooxxx
xxxoooxxxx
xxxxoxxxxx
xxxxxxxxxx
xxxxoxxxxx
xxxoooxxxx
xxoooooxxx
xxxxxxxxxx
__________________________________
output
[['1', '1', '1', '1', '1', '1', '1', '1', '1', '1'], ['1', '1', '1', '1', '1', '1', '1', '1', '1', '1'], ['1', '1', '1', '1', '1', '1', '1', '1', '1', '1'], ['1', '1', '1', '1', '1', '1', '1', '1', '1', '1'], ['1', '1', '1', '1', '1', '1', '1', '1', '1', '1'], ['1', '1', '1', '1', '1', '1', '1', '1', '1', '1'], ['1', '1', '1', '1', '1', '1', '1', '1', '1', '1'], ['1', '1', '1', '1', '1', '1', '1', '1', '1', '1'], ['1', '1', '1', '1', '1', '1', '1', '1', '1', '1'], ['1', '1', '1', '1', '1', '1', '1', '1', '1', '1']]
(任意に取り出した1地点を"1"とする
→それに隣接する”o"地点を"1" (再帰ループ)
→操作が完了したのち、"o"の個数がゼロならYes、それ以外なら地点を再取得
というような、プログラムを作ろうとしています)
inputから取り出した情報を変数A、変数field=Aとして変数filedに対してdfsを実行しているため、変数Aは変わらないと思うのですが、操作後のAをprintするとなぜかAが変わってしまいます。。
ごく初歩的なミスだとは思うのですが、ご教授いただけると幸いです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/01/19 12:27