#include<iostream> #include<cstdio> #include<cmath> #include<map> #define db(a) \ cout << #a << " = " << a << endl #define db2(a, b) \ cout << #a << " = " << a << " " << #b << " = " << b << endl #define inf (1<<30) #define foreach(it, m) \ for (typeof(m.begin()) it = m.begin(); it != m.end(); it++) #define MAX 2048 using namespace std; char M[MAX][MAX]; void solve(int n, int v, int h) { if (n == 1) { M[v][h] = '/'; M[v - 1][h + 1] = '/'; M[v - 1][h + 2] = '\\'; M[v][h + 1] = '_'; M[v][h + 2] = '_'; M[v][h + 3] = '\\'; } else { solve(n - 1, v, h); solve(n - 1, v - pow(2., n - 1), h + pow(2., n - 1)); solve(n - 1, v, h + pow(2., n)); } } int main() { #ifdef dennisbot freopen("in.in", "r", stdin); freopen("ou.out", "w", stdout); #endif int n; for (int i = 0; i < MAX; i++) { for (int j = 0; j < MAX; j++) { M[i][j] = ' '; } } string linea = ""; while (scanf("%d", &n) != EOF && n != 0) { for (int i = 0; i < pow(2., n + 1); i++) { for (int j = 0; j < pow(2., n + 1); j++) { M[i][j] = ' '; } } solve(n, pow(2., n) - 1, 0); for (int i = 0; i < pow(2., n) ; i++) { linea = ""; for (int j = 0; j < pow(2., n + 1); j++) { if (M[i][j] != ' ') { printf("%s%c",linea.c_str(), M[i][j]); linea = ""; } else linea += " "; } puts(""); } puts(""); } return 0; }
miércoles, 18 de abril de 2012
1406. The Sierpinski Fractal, tju online judge
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario