zoukankan      html  css  js  c++  java
  • 题目1161:Repeater(规律输出图形)

    题目1161:Repeater 题目链接:http://ac.jobdu.com/problem.php?pid=1161

    具体分析:https://github.com/zpfbuaa/JobduInCPlusPlus

    注意找到规律,因为打印图形都是规律性的!!!

    这里需要不断对二维数组进行更新操作

    每次都是幂乘结果!

    然后进行循环

    这个循环就是幂乘次数!

    2017年07月26日23:06:12

    参考代码:

    //
    //  1161 Repeater.cpp
    //  oj
    //
    //  Created by PengFei_Zheng on 05/04/2017.
    //  Copyright © 2017 PengFei_Zheng. All rights reserved.
    //
     
    #include <stdio.h>
    #include <iostream>
    #include <algorithm>
    #include <string.h>
    #include <cstdio>
    #include <stdlib.h>
    #include <cmath>
     
    using namespace std;
     
    int n,q;
    char buf[3001][3001];
    char sample[3001][3001];
    char board[6][6];
     
    void init(int a, int b, int n){
        for(int i = 0 ; i < n ; i ++){
            for(int j = 0 ; j < n ; j ++){
                buf[a * n + i][b * n + j]=' ';
            }
        }
    }
     
    void copy(int a, int b, int n){
        for(int i = 0 ; i < n ; i ++){
            for(int j = 0 ; j < n ; j++){
                buf[a * n + i][b * n + j] = sample[i][j];
            }
        }
    }
     
    void update(int n){
        for(int i = 0 ; i < n ; i ++){
            for(int j = 0 ; j < n ; j ++){
                sample[i][j]=buf[i][j];
            }
        }
    }
     
    int main(){
        while(scanf("%d",&n)!=EOF&&n!=0){
            getchar();
            for(int i = 0 ; i < n ; i ++){
                for(int j = 0 ; j < n ; j ++){
                    scanf("%c",&buf[i][j]);
                    board[i][j]=buf[i][j];
                }
                getchar();
            }
            scanf("%d",&q);
            int size = n ;
            for(int k = 2 ; k <= q ; k++){
                update(size);
                for(int i = 0 ; i < n ; i++){
                    for(int j = 0; j < n ; j++){
                        if(board[i][j]==' ')
                            init(i,j,size);
                        else
                            copy(i,j,size);
                    }
                }
                size = pow(n,k);
            }
            for(int i = 0 ; i < size ; i ++){
                for(int j = 0 ; j < size ; j ++){
                    printf("%c",buf[i][j]);
                }
                cout<<endl;
            }
        }
        return 0;
    }
     
    /**************************************************************
        Problem: 1161
        User: zpfbuaa
        Language: C++
        Result: Accepted
        Time:210 ms
        Memory:19200 kb
    ****************************************************************/
  • 相关阅读:
    filter
    列表生成式
    迭代
    切片:练习
    Python FAQ
    活在深圳
    “30岁年薪20万算不算很失败?”人民日报这样回答
    ASP.NET Core 运行原理解剖[1]:Hosting
    Kotlin 初窥门径[2]:流程控制
    Kotlin 初窥门径[1]:基础概念
  • 原文地址:https://www.cnblogs.com/zpfbuaa/p/6680422.html
Copyright © 2011-2022 走看看