zoukankan      html  css  js  c++  java
  • 题目1161:Repeater

    题目1161:Repeater

    时间限制:1秒
    内存限制:32 兆
    特殊判题:
    提交:742
    解决:249



     
    题目描述:

    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

    # #     # #
     #         #
    # #     # #
         # #  
          #   
         # #  
    # #    # #
     #        #
    # #    # #

    输入:

    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.

    输出:

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

    样例输入:
    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     
    
     

    递归:

    #include<stdio.h>
    int n;
    char temp[5][5];
    char p[3001][3001];
    void printblank(int q,int k,int l)
    {
        int sum=1;
        for (int i=0;i<q;i++)
            sum=sum*n;
        for (int i=0;i<sum;i++)
         for (int j=0;j<sum;j++)
             p[k+i][l+j]=' ';
    }
    void print(int q,int k,int l)
    {
        if (q==1)
        {
            for (int i=0;i<n;i++)
                for (int j=0;j<n;j++)
                    p[k+i][l+j]=temp[i][j];
        }else
        {
            int sum=1;
            for (int i=0;i<q;i++)
                sum=sum*n;
            for (int i=0;i<n;i++)
             for (int j=0;j<n;j++)
             {
                 int ki=i*sum/n;
                 int kj=j*sum/n;
                 if (temp[i][j]==' ') printblank(q-1,k+ki,l+kj);
                        else print(q-1,k+ki,l+kj);
             }
        }
    }
    int main()
    {
        int q;
        while(scanf("%d",&n)!=EOF)
        {
            getchar();
            if (n==0) continue;
            for (int i=0;i<n;i++)
            {
                for(int j=0;j<n;j++)
                {
                    scanf("%c",&temp[i][j]);
                }
                getchar();
            }
            scanf("%d",&q);
            print(q,0,0);
            int sum=1;
            for (int i=0;i<q;i++)
                sum=sum*n;
            for (int i=0;i<sum;i++)
            {
                for (int j=0;j<sum;j++)
                    printf("%c",p[i][j]);
                printf("
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    如何在DBGrid中能支持多项记录的选择
    How to create a OnCellDblClick for Delphi's TDBGrid
    如何在DBGrid里实现Shift+“选择行”区间多选的功能!
    DBGrid中Shift多选
    代码校验工具 SublimeLinter 的安装与使用
    jquery压缩图片插件
    React 入门最好的实例-TodoList
    前端切图
    提升前端效率的方式
    单页面应用的痛点
  • 原文地址:https://www.cnblogs.com/Secontao/p/3597955.html
Copyright © 2011-2022 走看看