zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    当前读与快照读
    Oracle临时表(Temporary Table)
    DG一主两备搭建
    配置dg broker
    源码编译安装PostgreSQL(pg12)
    Troubleshooting ORA-00600 [ORA_NPI_ERROR] ORA-00600: internal error code [kffilCreate01]
    mysql多实例配置(多配置文件)
    mysql多实例配置(单配置文件)
    Fixed Views Definitions in Oracle Database 11.2
    charles 禁用Cookies /Block Cookies Settings
  • 原文地址:https://www.cnblogs.com/Fatedayt/p/2432844.html
Copyright © 2011-2022 走看看