文章目录
- 方豆子
- 问题建模
- 问题分析
- 代码
 
 
 
方豆子



问题建模
给定一个整数n,要求输出n级好豆豆,n级好豆豆由3个n-1级好豆豆和1个n-1级坏豆豆组成,已经给出了1级好豆豆和1级坏豆豆。
问题分析
由于最终的豆豆是由其上一级的豆豆产生的,则可以考虑递归上级豆豆得到最终豆豆每一个位置所属的字符
代码
#include<bits/stdc++.h>
#define x first
#define y second
#define C(i) str[0][i]!=str[1][i]
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const int N =(3<<10), P = 2048;
char str[N+1][N+1];
void Getbean(int x,int y,int n,int d){
    if(n==1){
        for(int i=x;i<x+6;i++){
            for(int j=y;j<y+6;j++){
                if(i<x+3||j<y+3){
                    if(d)   str[i][j]='.';
                    else str[i][j]='*';   
                }else {
                    if(d)   str[i][j]='*';
                    else str[i][j]='.';
                } 
            }
        }
        return ;
    }
    n--;
    Getbean(x,y,n,d^1);
    Getbean(x,y+(3<<n),n,d^1);
    Getbean(x+(3<<n),y,n,d^1);
    Getbean(x+(3<<n),y+(3<<n),n,d);
}
void solve() {
    int n;
    cin >>n;
    Getbean(0,0,n,0);
    for(int i=0;i<(3<<n);i++){
        cout <<str[i] <<"\n";
    }
}   
int main() {
    int t = 1;
    //cin >> t;
    while (t--) solve();
    return 0;
}


















