题解 | #蛇形矩阵#
蛇形矩阵
https://www.nowcoder.com/practice/649b210ef44446e3b1cd1be6fa4cab5e
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<int>> a(n, vector<int>(n,0)); a[0][0] = 1; int m; for(int i=0; i<n; i++){ m=n-i; if(i!=0) a[i][0] = a[i-1][0] + i; for(int j=0; j<m; j++){ if(j!=0)a[i][j] = a[i][j-1] + j + 1 + i; cout << a[i][j] << " "; } cout << endl; } return 0; } // 64 位输出请用 printf("%lld")