$Poj2083/AcWing118\ Fractal$ 模拟

$AcWing$

$Sol$

一年前做过差不多的南蛮图腾,当时做出来还是很有成就感的$OvO$

$N<=7$,就是模拟模拟,预处理一下,$over$

$Code$

#include<bits/stdc++.h>
#define il inline
#define Rg register
#define go(i,a,b) for(Rg int i=a;i<=b;++i)
#define yes(i,a,b) for(Rg int i=a;i>=b;--i)
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define db double
using namespace std;
il int read()
{
    Rg int x=0,y=1;char c=getchar();
    while(c<‘0‘||c>‘9‘){if(c==‘-‘)y=-1;c=getchar();}
    while(c>=‘0‘&&c<=‘9‘){x=(x<<1)+(x<<3)+c-‘0‘;c=getchar();}
    return x*y;
}
char as[8][730][730];
il int ksm(int x,int y){Rg int ret=1;while(y){if(y&1)ret*=x;x*=x;y>>=1;}return ret;}
il void init()
{
    as[1][1][1]=‘X‘;
    go(n,2,7)
    {
        Rg int qwq=ksm(3,n-2);
        go(i,1,qwq)
        {
            go(j,1,qwq)as[n][i][j]=as[n][i][j+qwq*2]=as[n-1][i][j];
            go(j,qwq+1,2*qwq)as[n][i][j]=‘ ‘;
        }
        go(i,qwq+1,qwq*2)
        {
            go(j,1,qwq)as[n][i][j]=as[n][i][j+qwq*2]=‘ ‘;
            go(j,qwq+1,2*qwq)as[n][i][j]=as[n-1][i-qwq][j-qwq];
        }
        go(i,qwq*2+1,qwq*3)
        {
            go(j,1,qwq)as[n][i][j]=as[n][i][j+qwq*2]=as[n-1][i-qwq*2][j];
            go(j,qwq+1,2*qwq)as[n][i][j]=‘ ‘;
        }
    }
}
int main()
{
    init();
    while(1)
    {
        Rg int n=read();if(n==-1)break;
        Rg int qwq=ksm(3,n-1);
        go(i,1,qwq){go(j,1,qwq)printf("%c",as[n][i][j]);printf("\n");}
        printf("-\n");
    }
    return 0;
}

原文地址:https://www.cnblogs.com/forward777/p/11279274.html

时间: 2024-10-07 23:05:46