(简单递归3.4.1)POJ 2083 Fractal(分形图的打印)

来源:互联网 发布:国家网络管理局 编辑:程序博客网 时间:2024/05/29 04:00
#include <iostream>#include <cstdio>#include <cmath>using namespace std;const int maxn = 10000;char map[maxn][maxn];//n :度数void prepare(int n, int x, int y) {if (n == 1) {//递归边界map[x][y] = 'X';return;}//以下是搜索范围,共5各组成部分int size = (int)pow(3.0,n-2);//n-2 :规模prepare(n - 1, x, y);//左上角prepare(n - 1, x , y + size * 2);//右上角prepare(n - 1, x + size, y + size);//中间prepare(n - 1, x + size * 2, y);//左下角prepare(n - 1, x + size * 2, y + size * 2);//右下角}int main() {int n;while (scanf("%d", &n) != EOF, n != -1) {int i, j;int size = (int) pow(3.0, n - 1);//度为n的分形图的规模是3^(n-1)                //他是一个度为n,大小为size*size的图//初始化for (i = 1; i <= size; ++i) {for (j = 1; j <= size; ++j) {map[i][j] = ' ';}}prepare(n, 1, 1);for (i = 1; i <= size; ++i) {//打印printf("%s\n", map[i]+1);}printf("-\n");}return 0;}