其他分享
首页 > 其他分享> > AcWing 118. 分形

AcWing 118. 分形

作者:互联网

传送门

#include <bits/stdc++.h>

using namespace std;
int ans[3010][3010];

int main() {
    int n;
    while (cin >> n) {
        if (n == -1)
            break;
        ans[1][1] = 1;
        int len = pow(3.0, n - 1);
        for (int k = 1; k < len; k *= 3) {
            for (int i = 1; i <= k; i++) {
                for (int j = 1; j <= k; j++) {
                    ans[i + 2 * k][j] = ans[i][j + 2 * k] = ans[i][j];
                    ans[i + k][j + k] = ans[i + 2 * k][j + 2 * k] = ans[i][j];
                }
            }
        }
        for (int i = 1; i <= len; i++) {
            for (int j = 1; j <= len; j++) {
                if (ans[i][j])
                    cout << "X";
                else
                    cout << " ";
            }
            cout << endl;
        }
        puts("-");
    }
    return 0;
}

标签:std,int,3010,len,分形,ans,main,118,AcWing
来源: https://blog.csdn.net/xiao__hei__hei/article/details/100731259