#include <iostream>
using namespace std;
const int pows[12] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048};
int n, m;
bool mps[20][20];
int spc[20];
int qRead() {
int x = 0;
char ch = getchar();
while (!isdigit(ch)) {
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x;
}
int main() {
ios::sync_with_stdio(false);
n = qRead();
m = qRead();
for (int i = 1; i <= m; i++) {
int x, y;
x = qRead();
y = qRead();
mps[x][y] = true;
}
if (n == 1) {
if (mps[1][1]) {
cout << ' ';
}
else {
cout << 'o';
}
return 0;
}
spc[0] = 1;
spc[1] = 2;
for (int i = 2; i < 20; i++) {
spc[i] = spc[i - 1] * 2 + 1;
}
for (int i = 1; i < n; i++) {
int oct = pows[i - 1];
for (int j = 1; j <= oct; j++) {
for (int k = 1; k <= spc[n - i]; k++) {
cout << ' ';
}
if (mps[i - 1][(j + 1) / 2]) {
mps[i][j] = true;
}
if (mps[i][j]) {
cout << ' ';
}
else {
cout << 'o';
}
for (int k = 1; k <= spc[n - i]; k++) {
cout << ' ';
}
cout << ' ';
}
cout << endl;
for (int j = 1; j <= spc[n - i - 1]; j++) {
for (int nodes = 1; nodes <= oct; nodes++) {
for (int k = j; k <= spc[n - i] - 1; k++) {
cout << ' ';
}
if (mps[i][nodes] || mps[i + 1][nodes * 2 - 1]) {
cout << ' ';
}
else {
cout << '/';
}
for (int k = 1; k <= j - 1; k++) {
cout << ' ';
}
cout << ' ';
for (int k = 1; k <= j - 1; k++) {
cout << ' ';
}
if (mps[i][nodes] || mps[i + 1][nodes * 2]) {
cout << ' ';
}
else {
cout << '\\';
}
for (int k = j; k <= spc[n - i] - 1; k++) {
cout << ' ';
}
cout << ' ';
}
cout << endl;
}
}
int ot = pows[n - 2];
for (int i = 1; i <= ot; i++) {
if (mps[n - 1][i]) {
cout << " ";
continue;
}
if (mps[n][i * 2 - 1]) {
cout << ' ';
}
else {
cout << 'o';
}
cout << " ";
if (mps[n][i * 2]) {
cout << ' ';
}
else {
cout << 'o';
}
cout << ' ';
}
return 0;
}
主要是想找规律,看看每次输出多少空格。
记录在:https://www.luogu.com.cn/record/58317007
有什么建议吗?
谢谢!