5 条题解

  • 0
    @ 2026-7-19 11:23:02
    
    ```#include <iostream>
    #include <cmath>
    #include <string.h>
    using namespace std;
    #define LL long long
    const int N = 1e5 + 10;
    const int INF = 0x3f3f3f3f;
    char a[1000][1000];
    void f(int x , int y , int n)
    {
    	if(n == 1)
    	{
    		a[x][y] = 'X';
    		return ;
    	}
    	f(x,y,n-1);
    	f(x,y+pow(3,n-2)*2,n-1);
    	f(x+pow(3,n-2),y+pow(3,n-2),n-1);
    	f(x+pow(3,n-2)*2,y,n-1);
    	f(x+pow(3,n-2)*2,y+pow(3,n-2)*2,n-1);
    }
    int main()
    {
    	int n;
    	memset(a,' ',sizeof( a));
    	while(cin >> n && ~n)
    	{
    		f(0 , 0 , n);
    		for(int i = 0 ; i < pow(3,n-1) ; i++)
    		{
    			for(int j = 0 ; j < pow(3,n-1) ; j++)
    				printf("%c", a[i][j]);
    			puts("");
    		}
    		puts("-");
    	}
    }

    信息

    ID
    29
    时间
    1000ms
    内存
    128MiB
    难度
    2
    标签
    递交数
    316
    已通过
    195
    上传者