AcWing 755. 平方矩阵 III
原题链接
简单
作者:
杨根思
,
2024-11-23 12:28:09
,
所有人可见
,
阅读 1
drawing from topleft corner
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
int main() {
while (1) {
int dimension = 1;
cin >> dimension;
if (dimension == 0) break;
int f[dimension][dimension];
int topleft = 0;
for (topleft = 0; topleft < dimension; topleft++) {
int xi = topleft;
int yi = topleft;
int value = pow(pow(2, topleft), 2);
f[xi][yi] = value;
for (int x = xi + 1; x < dimension; x++) {
f[x][yi] = value * 2;
value *= 2;
}
value = pow(pow(2, topleft), 2);
for (int y = yi + 1; y < dimension; y++) {
f[xi][y] = value * 2;
value *= 2;
}
}
for (int i = 0; i < dimension; i++) {
for (int j = 0; j < dimension; j++) {
printf("%d ", f[i][j]);
}
cout << "\n";
}
cout << "\n";
}
return 0;
}