Poj 2083 fractal sub-governance + Recursion

Source: Internet
Author: User

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 ");}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.