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;
    }
  • 相关阅读:
    软件开发人员的简历项目经验怎么写?
    mapreduce 多种输入
    lnmp如何实现伪静态,默认目录伪静态
    LNMP环境中WordPress程序伪静态解决方案
    wordpress必装的插件 wp最常用的十个插件
    debian系统下改语言设置
    Centos7 开启端口
    EventProcessor与WorkPool用法--可处理多消费者
    Disruptor入门
    Disruptor初级入门
  • 原文地址:https://www.cnblogs.com/Secontao/p/3597955.html
Copyright © 2011-2022 走看看