zoukankan      html  css  js  c++  java
  • 暑假集训每日一题 0730 Repeater(杂题)

    Description

    Harmony is indispensible in our daily life and no one can live without it----may be Facer is the only exception. One day it is rumored that repeat painting will create harmony and then hundreds of people started their endless drawing. Their paintings were based on a small template and a simple method of duplicating. Though Facer can easily imagine the style of the whole picture, but he cannot find the essential harmony. Now you need to help Facer by showing the picture on computer.

    You will be given a template containing only one kind of character and spaces, and the template shows how the endless picture is created----use the characters as basic elements and put them in the right position to form a bigger template, and then repeat and repeat doing that. Here is an example.


    # #

     #      <-template

    # #

    So the Level 1 picture will be


    # #

     #

    # #

    Level 2 picture will be



    # #   # #

     #     #

    # #   # #

       # #  

        #   

       # #  

    # #   # #

     #     #

    # #   # #

    Input

    The input contains multiple test cases.
    The first line of each case is an integer N, representing the size of the template is N*N (N could only be 3, 4 or 5).
    Next N lines describe the template.
    The following line contains an integer Q, which is the Scale Level of the picture.
    Input is ended with a case of N=0.
    It is guaranteed that the size of one picture will not exceed 3000*3000.

    Output

    For each test case, just print the Level Q picture by using the given template.

    Sample Input

    3
    # #
     #
    # #
    1
    3
    # #
     #
    # #
    3
    4
     oo
    o  o
    o  o
     oo
    2
    0

    Sample Output

    # #
     #
    # #
    # #   # #         # #   # #
     #     #           #     #
    # #   # #         # #   # #
       # #               # #   
        #                 #    
       # #               # #   
    # #   # #         # #   # #
     #     #           #     #
    # #   # #         # #   # #
             # #   # #         
              #     #          
             # #   # #         
                # #            
                 #             
                # #            
             # #   # #         
              #     #          
             # #   # #         
    # #   # #         # #   # #
     #     #           #     #
    # #   # #         # #   # #
       # #               # #   
        #                 #    
       # #               # #   
    # #   # #         # #   # #
     #     #           #     #
    # #   # #         # #   # #
         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    

    View Code
    #include <stdio.h>
    #include <math.h>
    #define N 3001
    int n,cnt;
    char map[6][6];
    char ans[N][N];
    void Print(int x,int y)
    {
        int i,j;
        for(i=0;i<n;i++)
        {
            for(j=0;j<n;j++)    ans[i+x][j+y]=map[i][j];
        }
    }
    void PrintSpace(int x,int y,int d)
    {
        int i,j;
        for(i=0;i<d;i++)
        {
            for(j=0;j<d;j++)    ans[i+x][j+y]=' ';
        }
    }
    void PrintAns(int x,int y,int cnt)
    {
        int d=(int)pow(n,cnt-1);
        if(cnt==1)
        {
            Print(x,y);
            return;
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(map[i][j]==' ')  PrintSpace(x+i*d,y+j*d,d);
                else    PrintAns(x+i*d,y+j*d,cnt-1);
            }
        }
    }
    int main()
    {
        int i,j;
        while(scanf("%d",&n),n)
        {
            for(i=0;i<n;i++)
            {
                getchar();
                for(j=0;j<n;j++)    scanf("%c",&map[i][j]);
            }
            scanf("%d",&cnt);
            PrintAns(0,0,cnt);
            int d=(int)pow(n,cnt);
            for(i=0;i<d;i++)
            {
                for(j=0;j<d;j++)    printf("%c",ans[i][j]);
                puts("");
            }
        }
        return 0;
    }
  • 相关阅读:
    洛谷 P1219 八皇后【经典DFS,温习搜索】
    洛谷 P1972 [SDOI2009]HH的项链【莫队算法学习】
    hihoCoder #1015 : KMP算法【KMP裸题,板子】
    UVa 10341
    UVa 11461
    Uva
    BZOJ 3097: Hash Killer I【构造题,思维题】
    BZOJ 1207: [HNOI2004]打鼹鼠【妥妥的n^2爆搜,dp】
    BZOJ 1800: [Ahoi2009]fly 飞行棋【思维题,n^4大暴力】
    新版百度指数2013-12-23正式上线
  • 原文地址:https://www.cnblogs.com/algorithms/p/2615623.html
Copyright © 2011-2022 走看看