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;
    }
  • 相关阅读:
    Asp.Net2.0中的缓存
    webpartzone无法显示最小化和关闭按钮?
    TransactionScope分布式事务和非分布式事务
    JS获取GET参数的两种方法
    js 文件上传下载功能
    android动态设置布局LayoutInflater的使用详解
    Eclipse大括号换行显示
    Java强引用、 软引用、 弱引用、虚引用(转载)
    Android扭曲图像(水面落叶壁纸初步实现)
    win7系统自带的屏幕录制软件
  • 原文地址:https://www.cnblogs.com/algorithms/p/2615623.html
Copyright © 2011-2022 走看看