Skip to content

Instantly share code, notes, and snippets.

@tch69
Created November 14, 2024 14:33
Show Gist options
  • Save tch69/20de860014280cfae22139a4c35cf631 to your computer and use it in GitHub Desktop.
Save tch69/20de860014280cfae22139a4c35cf631 to your computer and use it in GitHub Desktop.
Kim tự tháp bị lỏ
#include <iostream>
#include <algorithm>
using namespace std;
int
main(void)
{
int n; cin >> n;
int a[n][2*n - 1];
fill(a[0], a[0] + n*(2*n - 1), 0);
int i, j, k;
for (i = 0; i < n; i++) {
k = 0;
for (j = i; j < 2 * n - 1; j += 2) {
if (i == j)
a[i][j] = 1;
else {
// Phuơng trình lồn
a[i][j] = a[i][j - 2] + 2 * (n - 1) - 2*i - 2*k;
}
if (j != n - 1)
a[i][2 * (n - 1) - j] = a[i][j];
if (j + 2 <= n - 1)
k++;
else
break;
}
}
for (j = 0; j < 2 * n - 1; j++) {
for (i = 0; i < n; i++) {
if (a[i][j])
cout << a[i][j] << " ";
else
cout << " ";
}
cout << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment