题目描述
blablabla
[code]
include[HTML_REMOVED]
include[HTML_REMOVED]
include[HTML_REMOVED]
include[HTML_REMOVED]
using namespace std;
const int N = 730;
int st[N][N],i,j;
int n;
//快速次幂算法
int power(int m,int k){
if(k == 0){
return 1;
}
int res = 1;
while(k){
if(k & 1){
res = res * m;
}
m = m * m;
k >>= 1;
}
return res;
}
//递归调用函数
void fun(int n,int x,int y){
if(n == 1){
st[x][y] = 1;
return ;
}
int len = power(3,n - 2);
fun(n - 1,x , y);
fun(n - 1,x + 2 * len , y);
fun(n - 1,x + len, y + len);
fun(n - 1,x , y + 2 * len);
fun(n - 1,x + 2 * len,y + 2 * len);
}
int main()
{
while(1)
{
cin >> n;
if(n == -1){
return 0;
}
fun(n,1,1);
for(i = 1; i <= power(3,n-1); i++){
for(j = 1; j <= power(3,n-1); j++){
if(st[i][j]){
cout << "X";
}else{
cout << " ";
}
}
puts("");
}
puts("-");
}
return 0;
}
[code]
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla