qq2931451523 @ 2021-12-07 21:15:03
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 1e3 + 100;
int Book[N][N];
void dfs(int k, int x, int y, int lx, int ly) // x,y是上一次画的图像坐标, lx, ly是偏移量
{
if (k <= 0) return ;
int len = pow(2, k);
int tx, ty; tx = ty = len / 2;
tx += lx; ty += ly;
int t;
if (x > tx & y > ty)
{
t = 4;
if (Book[tx][ty] || Book[tx + 1][ty] || Book[tx][ty + 1])
{
if (Book[tx][ty]) tx++, ty++, t = 1;
else if (Book[tx + 1][ty]) ty++, t = 3;
else if (Book[tx][ty + 1]) tx++, t = 2;
}
cout<<tx<<" "<<ty<<" "<<t<<endl;
}
else if (x > tx && y <= ty)
{
t = 3;
ty++;
if (Book[tx][ty] || Book[tx][ty - 1] || Book[tx + 1][ty])
{
if (Book[tx][ty]) tx++, ty--, t = 2;
else if (Book[tx][ty - 1]) tx++, t = 1;
else if (Book[tx + 1][ty]) ty--, t = 4;
}
cout<<tx<<" "<<ty<<" "<<t<<endl;
}
else if (x <= tx && y > ty)
{
t = 2;
tx++;
if (Book[tx][ty] || Book[tx - 1][ty] || Book[tx][ty + 1])
{
if (Book[tx][ty]) tx--, ty++, t = 3;
else if (Book[tx - 1][ty]) ty++, t = 1;
else if (Book[tx][ty + 1]) tx--, t = 4;
}
cout<<tx<<" "<<ty<<" "<<t<<endl;
}
else if (x <= tx && y <= ty)
{
t = 1;
tx++, ty++;
if (Book[tx][ty] || Book[tx][ty - 1] || Book[tx - 1][ty])
{
if (Book[tx][ty]) tx--, ty--, t = 4;
else if (Book[tx][ty - 1]) tx--, t = 3;
else if (Book[tx - 1][ty]) ty--, t = 2;
}
cout<<tx<<" "<<ty<<" "<<t<<endl;
}
Book[tx][ty] = 1;
if (t == 1) Book[tx][ty - 1] = Book[tx - 1][ty] = 1;
else if (t == 2) Book[tx][ty + 1] = Book[tx - 1][ty] = 1;
else if (t == 3) Book[tx][ty - 1] = Book[tx + 1][ty] = 1;
else if (t == 4) Book[tx][ty + 1] = Book[tx + 1][ty] = 1;
dfs(k - 1, tx, ty, lx, ly);
dfs(k - 1, tx, ty, lx, ly + len / 2);
dfs(k - 1, tx, ty, lx + len / 2, ly);
dfs(k - 1, tx, ty, lx + len / 2, ly + len / 2);
}
int main()
{
int x, y, k;
cin>>k>>x>>y;
Book[x][y] = 1;
dfs(k, x, y, 0, 0);
return 0;
}