Portal Fractal
I still remember that this question was the first week of the competition ~~~ Why can't I cut it out ~~ At that time, I tried againCode~~ Still do not understand
Today, I think that the idea of divide, conquer, and Recursion really solves this problem that has plagued me for a long time.
The original Article is like this.
X
-
X
X
X
-
X
X
X
X
X
X
X
X
X
This is the idea of recursive extra points.
Example 1: simple
Example 2: Add x
Example 3 is based on Example 2.
Extended ~~ To put it bluntly, it is composed of five Example 2
Post Code:
Wa twice (1) Note that the range of the character array is larger (2) From back to forward to the Space Note to use printf ("% s", a [I]); if the output of a single character times out ~
# Include <stdio. h> # include <string. h> # include <math. h ># include <iostream> using namespace STD; char a [800] [800]; int fun (int x, int y, int N) {If (n = 2) {// take the figure in example 2 as the basic unit A [x] [Y] = 'X'; A [x + 1] [Y + 1] = 'X '; A [x-1] [Y-1] = 'X'; A [x + 1] [Y-1] = 'X'; A [x-1] [Y + 1] = 'X '; return 1;} int add = (INT) (POW (3, N-2) + 0.01); // determine the location of each offset fun (X, Y, n-1 ); // recursive thinking fun (x + Add, Y + Add, n-1); fun (X-add, Y-add, n-1); fun (x + add, y-add, n-1); fun (X-add, Y + Add, n -1);} int main () {// freopen ("a.txt", "r", stdin); // freopen ("B .txt", "W", stdout ); int N; while (scanf ("% d", & N) & (n! =-1) {int Pos = (INT) (POW (3, n-1) + 0.01); memset (A, '', sizeof (char) * (Pos + 10) * 820); int x = POS/2, y = POS/2; // determine the position of center X if (n = 1) {printf ("x \ n"); printf ("-\ n"); continue;} fun (X, Y, n); For (INT I = 0; I <Pos; I ++) {int Len = POS + 10; while (A [I] [Len] = '') {Len --;} A [I] [Len + 1] = '\ 0'; printf ("% s \ n", a [I]);} printf ("-\ n ");}}