Skip to content

Commit

Permalink
ABC357C Sierpinsky Carpet
Browse files Browse the repository at this point in the history
  • Loading branch information
Vicfred committed Jun 10, 2024
1 parent 3e15e87 commit 088047d
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions atcoder/abc357c_sierpinski_carpet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Vicfred
// https://atcoder.jp/contests/abc357/tasks/abc357_c
// implementation, recursion
#include <cmath>
#include <iostream>

using namespace std;

int n;
char grid[1000][1000];

void dfs(int n, int x, int y) {
if (n == 0) {
grid[x][y] = '#';
return;
}
dfs(n - 1, x, y);
dfs(n - 1, x, y + pow(3, n - 1));
dfs(n - 1, x, y + pow(3, n - 1) * 2);
dfs(n - 1, x + pow(3, n - 1), y);
dfs(n - 1, x + pow(3, n - 1), y + pow(3, n - 1) * 2);
dfs(n - 1, x + pow(3, n - 1) * 2, y);
dfs(n - 1, x + pow(3, n - 1) * 2, y + pow(3, n - 1));
dfs(n - 1, x + pow(3, n - 1) * 2, y + pow(3, n - 1) * 2);
for (int i = 0; i < pow(3, n - 1); ++i) {
for (int j = 0; j < pow(3, n - 1); ++j) {
grid[x + (int)pow(3, n - 1) + i][y + (int)pow(3, n - 1) + j] = '.';
}
}
}

int main() {
cin >> n;
dfs(n, 1, 1);
for (int i = 1; i <= pow(3, n); ++i) {
for (int j = 1; j <= pow(3, n); ++j) {
cout << grid[i][j];
}
cout << endl;
}
return 0;
}

0 comments on commit 088047d

Please sign in to comment.