• ZOJ3507 Fractal


    ZOJ3507 Fractal

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    A fractal is an object or quantity that displays self-similarity, in a somewhat technical sense, on all scales. The object need not exhibit exactly the same structure at all scales, but the same "type" of structures must appear on all scales. Given an m * n bitmap bmp, your job is to draw a "k-F bitmap of bmp". A "k-F bitmap of bmp" is made up of m * n sub-bitmap with blank bit in bmp replaced by blank region and no blank bit int bmp replaced by "(k-1)-F bitmap of bmp", and "1-F bitmap of bmp" is bmp itself. More details in sample.

    Input

    There will be multiple cases. Process to the End Of File.

    Each case bigin with two positive integer m and n both less than 12, then a m * n bitmap bmp with trailing blanks if necessary. At last, a positive integer k no more than 12 indicate the desired bitmap.

    Ouput

    First ouput "Fractal #%d:" in a line where "%d" is the case id, ans output the answer to this case. Seperate cases with a blank line. No trailing blanks are allowed in the output.

    Sample Input

    1 3
    ## 
    4
    3 3
    X X
     X 
    X X
    3
    6 6
    +----+
    | /\ |
    |/  \|
    | /\ |
    | \/ |
    +----+
    2
    

    Sample Output

    Fractal #1:
    ## ##    ## ##             ## ##    ## ##
    
    Fractal #2:
    X X   X X         X X   X X
     X     X           X     X
    X X   X X         X X   X X
       X X               X X
        X                 X
       X X               X X
    X X   X X         X X   X X
     X     X           X     X
    X X   X X         X X   X X
             X X   X X
              X     X
             X X   X X
                X X
                 X
                X X
             X X   X X
              X     X
             X X   X X
    X X   X X         X X   X X
     X     X           X     X
    X X   X X         X X   X X
       X X               X X
        X                 X
       X X               X X
    X X   X X         X X   X X
     X     X           X     X
    X X   X X         X X   X X
    
    Fractal #3:
    +----++----++----++----++----++----+
    | /\ || /\ || /\ || /\ || /\ || /\ |
    |/  \||/  \||/  \||/  \||/  \||/  \|
    | /\ || /\ || /\ || /\ || /\ || /\ |
    | \/ || \/ || \/ || \/ || \/ || \/ |
    +----++----++----++----++----++----+
    +----+      +----++----+      +----+
    | /\ |      | /\ || /\ |      | /\ |
    |/  \|      |/  \||/  \|      |/  \|
    | /\ |      | /\ || /\ |      | /\ |
    | \/ |      | \/ || \/ |      | \/ |
    +----+      +----++----+      +----+
    +----++----+            +----++----+
    | /\ || /\ |            | /\ || /\ |
    |/  \||/  \|            |/  \||/  \|
    | /\ || /\ |            | /\ || /\ |
    | \/ || \/ |            | \/ || \/ |
    +----++----+            +----++----+
    +----+      +----++----+      +----+
    | /\ |      | /\ || /\ |      | /\ |
    |/  \|      |/  \||/  \|      |/  \|
    | /\ |      | /\ || /\ |      | /\ |
    | \/ |      | \/ || \/ |      | \/ |
    +----+      +----++----+      +----+
    +----+      +----++----+      +----+
    | /\ |      | /\ || /\ |      | /\ |
    |/  \|      |/  \||/  \|      |/  \|
    | /\ |      | /\ || /\ |      | /\ |
    | \/ |      | \/ || \/ |      | \/ |
    +----+      +----++----+      +----+
    +----++----++----++----++----++----+
    | /\ || /\ || /\ || /\ || /\ || /\ |
    |/  \||/  \||/  \||/  \||/  \||/  \|
    | /\ || /\ || /\ || /\ || /\ || /\ |
    | \/ || \/ || \/ || \/ || \/ || \/ |
    +----++----++----++----++----++----+
    *******************************************************************
    题目大意:给定一个n*m的位图,扩大k倍,满足分形的规律,输出图形。
    解体思路:博客久不更新了,把这道题放上来是因为感觉这道题太艺术了,很喜欢。分形,在我看来很好看啊。任何部分都和自己相似,美妙的。用递归就能实现。具体的看代码:
    //#pragma comment(linker,"STACK:65536000")
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <stdlib.h>
    #include <iostream>
    #include <queue>
    #include <stack>
    #include <string>
    #include <map>
    #include <vector>
    #include <algorithm>
    #define N 15
    #define M
    #define E
    #define inf 0x3f3f3f3f
    #define eps 1e-8
    #define linf (LL)1<<60
    #define dinf 1e20
    #define LL long long
    #define clr(a,b) memset(a,b,sizeof(a))
    #define D(a) ((a)*(a))
    using namespace std;
    
    int n,m,k;
    char gra[N][N];
    int nn[N],mm[N];
    
    char gc(int r,int c,int d)
    {
        if(d==1)return gra[r][c];
        if(gra[r/nn[d-1]][c/mm[d-1]]==' ')return ' ';
        return gc(r%nn[d-1],c%=mm[d-1],d-1);
    }
    
    int main()
    {
        //freopen("/home/fatedayt/in","r",stdin);
        //freopen("/home/fatedayt/out","w",stdout);
    	for(int h=0;;h++)
    	{
    	    if(scanf("%d%d",&n,&m)==EOF)break;
    	    if(h)puts("");
    	    printf("Fractal #%d:\n",h+1);
    	    getchar();
    	    for(int i=0;i<n;i++)
                gets(gra[i]);
            scanf("%d",&k);
            nn[0]=mm[0]=1;
            for(int i=1;i<=k;i++)
            {
                nn[i]=nn[i-1]*n;
                mm[i]=mm[i-1]*m;
            }
            for(int i=0;i<nn[k];i++)
            {
                int lim=-1;
                for(int j=mm[k]-1;j>=0;j--)
                    if(gc(i,j,k)!=' ')
                    {
                        lim=j;break;
                    }
                for(int j=0;j<=lim;j++)
                    printf("%c",gc(i,j,k));
                puts("");
            }
    	}
    	return 0;
    }
    
  • 相关阅读:
    Zend Studio下调试PHP的一点注意事项
    使用FTP出现中文乱码解决方案
    C++数据类型与C#对应表
    FineUI 开发B/S系统
    c#调用带输出参数的存储过程
    经典FormsAuthenticationTicket 分析
    C# Oracle数据库操作类实例详解
    如何使用C#的Hashtable[哈希表]
    对三层架构的理解
    C# 最简单的三层架构实例 ——转载自网易博客
  • 原文地址:https://www.cnblogs.com/Fatedayt/p/2432844.html
Copyright © 2020-2023  润新知