リピータPOJ - 3768(フラクタル)

リピータ

POJ - 3768

ハーモニーは、私たちの日常生活に欠かせないし、誰もそれなしでは生きすることはできません----表面材は唯一の例外であるかもしれません。ある日リピート絵が調和を作成し、その後、何百人もの人々が彼らの無限の描画を開始したと噂されています。彼らの絵は、小さなテンプレートと複製の簡単な方法に基づいていました。けれども表面材は簡単に全体像のスタイルを想像することができますが、彼は基本的な調和を見つけることができません。今、あなたは、コンピュータ上の画像を示すことによって表面材を支援する必要があります。

あなたは、文字とスペースの一種のみを含むテンプレートが与えられますし、テンプレートは、基本的な要素として文字を使用し、より大きなテンプレートを形成するために、正しい位置に入れ、そして----無限の画像が作成される方法を示しています繰り返し、それをやって繰り返します。ここでは一例です。

    # #

 #      <-template

# #

だから、レベル1の画像になります

    # #

 #

# #

レベル2の絵になります

# #   # #

 #     #

# #   # #

   # #   

    #    

   # #   

# #   # #

 #     # 

# #   # #

入力

入力は複数のテストケースが含まれています。
それぞれの場合の最初の行は整数であるNテンプレートの大きさを表す、であるN(** N * Nはわずか3、4又は5であってもよいです)。
次のN行は、テンプレートを記述します。
次の行は、整数含まQ映像のスケールレベルです。
入力の場合に終了したN = 0。
一の画面のサイズは* 3000 3000を超えないことが保証されます。

出力

各テストケースの場合は、単にレベルの印刷Qの特定のテンプレートを使って絵を。

サンプル入力

3
# #
 # 
# #
1
3
# #
 # 
# #
3
4
 OO 
O  O
O  O
 OO 
2
0

サンプル出力


# #
 # 
# #
# #   # #         # #   # #
 #     #           #     # 
# #   # #         # #   # #
   # #               # #   
    #                 #    
   # #               # #   
# #   # #         # #   # #
 #     #           #     # 
# #   # #         # #   # #
         # #   # #         
          #     #          
         # #   # #         
            # #            
             #             
            # #            
         # #   # #         
          #     #          
         # #   # #         
# #   # #         # #   # #
 #     #           #     # 
# #   # #         # #   # #
   # #               # #   
    #                 #    
   # #               # #   
# #   # #         # #   # #
 #     #           #     # 
# #   # #         # #   # #
     OO  OO     
    O  OO  O    
    O  OO  O    
     OO  OO     
 OO          OO 
O  O        O  O
O  O        O  O
 OO          OO 
 OO          OO 
O  O        O  O
O  O        O  O
 OO          OO 
     OO  OO     
    O  OO  O    
    O  OO  O    
     OO  OO     

アイデア:

ミニッツ古典的な問題字型、

グラフィックス処理に小さなグラフィック多数の、小さなグラフィックも小さくグラフィックに続けます。

DFS再帰を使用して、パターンと現在のステップ(辺の長さ)のパターンサイズの左上隅の良い現在の座標を維持し、電流が第1層でありすることができ、第1の層は、直接場合、単位素子が割り当てられます。

個人的に私は比較的簡単に書く感じ。

詳細コードを参照してください。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) {a %= MOD; if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}

inline void getInt(int* p);
const int maxn = 3000 + 10;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/

bool s[maxn][maxn];
char a[maxn][maxn];
int x;
void dfs(int lx, int ly, int rx, int ry, int len, int st)
{
    // cout << lx << " " << ly << " " << rx << " " << ry << " " << len << " " << st << endl;
    if (len == 1)
    {
        s[lx][ly] = 1;
        return ;
    }
    int to = len / x;
    repd(i, 1, x)
    {
        rep(j, 0, x)
        {
            if (a[i][j] != ' ')
            {
                dfs(lx + (i - 1)*to, ly + (j)*to, lx + (i - 1)*to + to - 1, ly + (j)*to + to - 1, to, st - 1);
            }
        }
    }

}
char base;
int main()
{
    //freopen("D:\\code\\text\\input.txt","r",stdin);
    //freopen("D:\\code\\text\\output.txt","w",stdout);
    while (~scanf("%d", &x))
    {
        if (!x)
        {
            break;
        }
        // cin >> base;
        getchar();
        repd(i, 1, x)
        {
            gets(a[i]);
            // getline(cin, a[i]);
        }
        repd(i, 1, x)
        {
            rep(j, 0, x)
            {
                if (a[i][j] != ' ')
                {
                    base = a[i][j];
                }
//                cout<<a[i][j];
            }
//            cout<<endl;
        }
        // chu(base);
        int step;
        // cin >> step;
        scanf("%d", &step);
        int len = (int)(pow(x, step) + 0.5);
        dfs(1, 1, len, len, len, step);
        repd(i, 1, len)
        {
            repd(j, 1, len)
            {
                if (s[i][j])
                {
                    putchar(base);
                    // cout << base;
                } else
                {
                    putchar(' ');
                    // cout << ' ';
                }
                s[i][j] = 0;
            }
            putchar('\n');
            // cout << endl;
        }
    }

    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



おすすめ

転載: www.cnblogs.com/qieqiemin/p/11701382.html