• 暑假集训每日一题 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;
    }
  • 相关阅读:
    使用cmd命令行窗口操作SqlServer
    .net core compatibility windows & windows compatible Linux
    Microsoft Azure Tutorial: Build your first movie inventory web app with just a few lines of code
    Running ASP.NET Core applications on Windows Subsystem for Linux
    Simple Use IEnumerable<T>
    JSON in SQL Server 2016
    [开源 .NET 跨平台 Crawler 数据采集 爬虫框架: DotnetSpider] [一] 初衷与架构设计
    NotBacon
    Create an Azure SQL database in the Azure portal
    Cisco IP 电话 将它的voice mail 发送到手机
  • 原文地址:https://www.cnblogs.com/algorithms/p/2615623.html
Copyright © 2020-2023  润新知