1.https://codeforces.com/contest/2033/problem/B
這道題對每個測試樣例一個矩陣,求最小次數,觀察規律知道只要求最小值的和即可。程式碼如下:
for _ in range(int(input())):
n = int(input())
mp = [list(map(int,input().split())) for _ in range(n)]
s = 0
for d in range(-n+1,n):
mm = min(mp[i][i-d] for i in range(max(0,d),min(n,n+d)))
if mm < 0:
s += abs(mm)
print(s)
找到對角線的元素特點,mp[i][i-d]都可以想到,主要是後面的索引值要取正確,否則會錯。
2.https://codeforces.com/contest/2033/problem/C