C - Sierpinski carpet
https://atcoder.jp/contests/abc357/tasks/abc357_c
思路
开辟cells作为标记结果,
dfs递归调用对#进行标记。
Code
https://atcoder.jp/contests/abc357/submissions/54361221
int n; bool cells[800][800]; void dfs(int x, int y, int k){ if (k == 0){ cells[x][y] = true; return; } int step = pow(3, k-1); for(int i=0; i<3; i++){ for(int j=0; j<3; j++){ if (i == 1 && j == 1){ continue; } dfs(x+i*step, y+j*step, k-1); } } } void print(){ int limit = pow(3, n); for(int i=0; i<limit; i++){ for(int j=0; j<limit; j++){ cout << (cells[i][j]?"#":"."); } cout << endl; } } int main() { cin >> n; dfs(0, 0, n); print(); return 0; }
标签:Sierpinski,int,cells,dfs,abc357,carpet From: https://www.cnblogs.com/lightsong/p/18239067