zoukankan      html  css  js  c++  java
  • Codeforces 36B

    36B - Fractal

    思路:分形

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long 
    #define pb push_back
    #define mem(a,b) memset(a,b,sizeof(a))
    
    char mp[500][500];
    char c[10][10];
    void dfs1(int x,int y,int k,char color){
        if(k==0){
            mp[x][y]=color;
            return ;
        }
        if(color=='.'){
            dfs1(x,y,k-1,c[1][1]);
            dfs1(x+pow(2,k-1),y,k-1,c[2][1]); 
            dfs1(x,y+pow(2,k-1),k-1,c[1][2]);
            dfs1(x+pow(2,k-1),y+pow(2,k-1),k-1,c[2][2]);
        }
        else{
            dfs1(x,y,k-1,'*');
            dfs1(x+pow(2,k-1),y,k-1,'*'); 
            dfs1(x,y+pow(2,k-1),k-1,'*');
            dfs1(x+pow(2,k-1),y+pow(2,k-1),k-1,'*');
        }
    }
    void dfs2(int x,int y,int k,char color){
        if(k==0){
            mp[x][y]=color;
            return ;
        }
        if(color=='.'){
            dfs2(x,y,k-1,c[1][1]);
            dfs2(x+pow(3,k-1),y,k-1,c[2][1]); 
            dfs2(x,y+pow(3,k-1),k-1,c[1][2]);
            dfs2(x+pow(3,k-1),y+pow(3,k-1),k-1,c[2][2]);
            dfs2(x+2*pow(3,k-1),y,k-1,c[3][1]);
            dfs2(x+2*pow(3,k-1),y+pow(3,k-1),k-1,c[3][2]);
            dfs2(x+2*pow(3,k-1),y+2*pow(3,k-1),k-1,c[3][3]);
            dfs2(x,y+2*pow(3,k-1),k-1,c[1][3]);
            dfs2(x+pow(3,k-1),y+2*pow(3,k-1),k-1,c[2][3]);
        }
        else{
            dfs2(x,y,k-1,'*');
            dfs2(x+pow(3,k-1),y,k-1,'*'); 
            dfs2(x,y+pow(3,k-1),k-1,'*');
            dfs2(x+pow(3,k-1),y+pow(3,k-1),k-1,'*');
            dfs2(x+2*pow(3,k-1),y,k-1,'*');
            dfs2(x+2*pow(3,k-1),y+pow(3,k-1),k-1,'*');
            dfs2(x+2*pow(3,k-1),y+2*pow(3,k-1),k-1,'*');
            dfs2(x,y+2*pow(3,k-1),k-1,'*');
            dfs2(x+pow(3,k-1),y+2*pow(3,k-1),k-1,'*');
        }
    }
    int main(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        int n,k;
        cin>>n>>k;
        for(int i=1;i<=n;i++)cin>>(c[i]+1);
        if(n==2){
            dfs1(1,1,k,'.');
            for(int i=1;i<=pow(2,k);i++){
                puts(mp[i]+1);
            }
        } 
        else{
            dfs2(1,1,k,'.');
            for(int i=1;i<=pow(3,k);i++){
                puts(mp[i]+1);
            }
        } 
        return 0;
    } 
  • 相关阅读:
    codeforces 1060 B
    codeforces 1060 A
    牛客 国庆七天乐 day1 L
    BZOJ 1087: [SCOI2005]互不侵犯King
    codeforces 792CDivide by Three(两种方法:模拟、动态规划
    codeforces 797C Minimal string
    codeforces 110E Lucky Tree
    codeforces 798D
    2017福建省赛 FZU2272~2283
    Android -- Looper、Handler、MessageQueue等类之间关系的序列图
  • 原文地址:https://www.cnblogs.com/widsom/p/8425045.html
Copyright © 2011-2022 走看看