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;
    }
  • 相关阅读:
    Scala In 5 Years – My Prediction « GridGain – Real Time Big Data
    牛魔王珍满福拉面 北京团购网|京东团购
    Build WebKit On Windows 白果果白的专栏 博客频道 CSDN.NET
    fabulous
    Selenimu做爬虫 oscarxie 博客园
    EA gpl
    数据挖掘与Taco Bell编程
    test cpp could not compiled on ubuntu use g++,i'll tried lateor on win platform
    How to use ActiveRecord without Rails
    svn添加新项目管理并添加到trac 知识是一种越吃越饿的粮食 ITeye技术网站
  • 原文地址:https://www.cnblogs.com/Secontao/p/3597955.html
Copyright © 2011-2022 走看看