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;
    }
  • 相关阅读:
    类欧几里得入土总结 2
    【题解】AGC012C Tautonym Puzzle(人类智慧)
    51nod 1847 奇怪的数学题(min25)
    【题解】51nod1575 LCM and GCD (min25筛)
    【题解】P5163 WD与地图 (这题极好)
    Astronomia.cpp
    LOJ6609 无意识的石子堆 加强版 (容斥)
    【题解】AT2273 Addition and Subtraction Hard(DP)
    【题解】Another Coin Weighing Puzzle (构造)
    【题解】P3747 [六省联考2017]期末考试 (单位根反演)
  • 原文地址:https://www.cnblogs.com/algorithms/p/2615623.html
Copyright © 2011-2022 走看看