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;
    }
  • 相关阅读:
    android代码控制seekbar的样式
    在Android中显示GIF动画
    一个带动画效果的颜色选择对话框控件AnimatedColorPickerDialog
    史上最强Android 开启照相或者是从本地相册选中一张图片以后先裁剪在保存并显示的讲解附源码
    Linux System Programming note 8 ——File and Directory Management
    Spring它不支持依赖注入static静态变量
    举例说,在命令模式(Command Pattern)
    log4j 日志大小限制 分成30一个 不按日期分日志 按大小分成 按生产日期
    JavaScript获取路径
    awk与sed:关于多行的样本
  • 原文地址:https://www.cnblogs.com/algorithms/p/2615623.html
Copyright © 2011-2022 走看看