Topic Links:
http://poj.org/problem?id=2083
Title Description:
n = 1 o'clock, graph b[1] is X
n = 2 o'clock, graphic b[2] is x x
X
x x
So n, graphic b[n] is b[n-1] b[n-1]
B[N-1]
B[n-1] b[n-1]
Problem Solving Ideas:
The output is a rectangle, which is a rectangular!!!!!!, which is stored in a two-dimensional array with a recursive print graph.
Code:
1#include <cmath>2#include <cstdio>3#include <cstring>4#include <cstdlib>5 using namespacestd;6 #defineMAXN 7407 CharMAP[MAXN][MAXN];8 9 voidDFS (intNintXinty);Ten //N is b[n], (x, y) is b[n] the upper left point; One intMain () A { - intI, J, N; - while(SCANF ("%d", &n), n! =-1) the { - intm = (int) Pow (3, N-1); - for(i=0; i<=m; i++) - { + for(j=0; j<=m; J + +) -MAP[I][J] =' '; +map[i][m+1] =' /'; A } atDFS (N,0,0); - for(i=0; i<m; i++) - puts (map[i]); -printf ("-\n"); - } - return 0; in } - to voidDFS (intNintXinty) + { - if(n = =1) the { *Map[x][y] ='X'; $ return ;Panax Notoginseng } - intm = (int) Pow (3, N-2);//size of b[n-1] theDFS (N-1, x, y);//Up_left +DFS (N-1, X, y+2*M);//Up_right ADFS (N-1, X+m, y+m);//Middle theDFS (N-1, x+2*m, y);//Down_left +DFS (N-1, x+2*m, y+2*M);//Down_right -}
POJ 2083 Fractal Recursive graphics printing