ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

KY58 Repeater

2021-11-22 19:35:15  阅读:183  来源: 互联网

标签:OO picture Repeater int KY58 ++ template 模板


描述
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 NN (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 30003000.
输出描述:
For each test case, just print the Level Q picture by using the given template.
示例1
输入:
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     

题目大意:
给你一个仅包含一种字符和空格的模板,模板显示如何创建无尽的图片,将字符用作基本元素并将它们放在正确的位置以形成更大模板,然后不断进行该操作。
知识点: 暴力求解 模拟 递归
AC代码:

#include <bits/stdc++.h>

using namespace std;

int N;
char temp[10][10]; // 存放template模板
char picture[3005][3005]; // 存放最终picture

void draw(int Q, int a, int b) // 递归画每一个level
{
    if(Q == 1) // level1
    {
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                picture[a + i][b + j] = temp[i][j];
            }
        }
    }
    else
    {
        int unit = pow(N, Q - 1); // 以上一level为一个单元
        for (int i = 0; i < N; i++) // 遍历模板template
        {
            for (int j = 0; j < N; j++)
            {
                if(temp[i][j] != ' ')
                {
                    draw(Q - 1, a + i * unit, b + j * unit);
                }
            }
        }
    }
}

int main()
{
    while(cin >> N)
    {
        if(N == 0)
        {
            break;
        }
        getchar();
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                temp[i][j] = getchar();
            }
            getchar();
        }
        int Q;
        cin >> Q;
		
		for (int i = 0; i < 3005; i++)
        {
            for (int j = 0; j < 3005; j++)
            {
                picture[i][j] = ' ';
            }
        }
        int length = pow(N, Q); // column
        draw(Q, 0, 0);
        for(int i = 0; i < length; i++)
        {
            for(int j = 0; j < length; j++)
            {
                cout << picture[i][j];
            }
            cout << endl;
        }
    }
}

标签:OO,picture,Repeater,int,KY58,++,template,模板
来源: https://blog.csdn.net/qq_46620129/article/details/121478282

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有