https://zerojudge.tw/ShowProblem?problemid=f313
APCS 2020.10.17
這題比較要注意的是,先遷徙,再加總,如果邊遷徙邊作加總會算錯的唷,這題測資很善良的讓你知道邊遷邊加是錯的,如果是我就不會這麼善良了^.^。
解題程式碼如下:
如果有任何問題歡迎留言或來信討論。
import sys
a = []
r,c,k,m = tuple([int(i) for i in input().split()])
for i in range(r):
a.append([int(j) for j in input().split()])
for i in range(m):
b = [[0 for _ in range(c)] for _ in range(r)]
for j in range(r):
for l in range(c):
if a[j][l] != -1:
temp = int(a[j][l] / k)
if j-1 >= 0 and a[j-1][l] != -1:
b[j][l] -= temp
b[j-1][l] += temp
if j+1 < r and a[j+1][l] != -1:
b[j][l] -= temp
b[j+1][l] += temp
if l-1 >= 0 and a[j][l-1] != -1:
b[j][l] -= temp
b[j][l-1] += temp
if l+1 < c and a[j][l+1] != -1:
b[j][l] -= temp
b[j][l+1] += temp
for j in range(r):
for l in range(c):
if a[j][l] == -1: continue
a[j][l] += b[j][l]
maxI = -1
minI = sys.maxsize
for i in range(r):
for j in range(c):
if a[i][j] == -1: continue
if a[i][j] > maxI:
maxI = a[i][j]
if a[i][j] < minI:
minI = a[i][j]
print(minI)
print(maxI)
沒有留言:
張貼留言