알고리즘 경기 보전 분치 알고리즘 결핍 바둑판
1618 단어 알고리즘 경연 보전분치 알고리즘
#include
using namespace std;
int chess[1050][1050];
int k, x, y;
int tmp;
void lt(int x, int y)
{
chess[x][y + 1] = 4;
chess[x + 1][y + 1] = 4;
chess[x + 1][y] = 4;
}
void lb(int x, int y)
{
chess[x - 1][y] = 2;
chess[x - 1][y + 1] = 2;
chess[x][y + 1] = 2;
}
void rt(int x, int y)
{
chess[x][y - 1] = 3;
chess[x + 1][y - 1] = 3;
chess[x + 1][y] = 3;
}
void rb(int x, int y)
{
chess[x - 1][y - 1] = 1;
chess[x][y - 1] = 1;
chess[x - 1][y] = 1;
}
void work(int x1,int y1,int x2,int y2,int kk)
{
int px, py;
if (kk == 0)
return;
for (int i = x1; i <= x2; i++)
{
for (int j = y1; j <= y2; j++)
if (chess[i][j])
{
px = i;
py = j;
}
}
if ((x1 + x2) / 2 >= px)
{
if ((y1 + y2) / 2 >= py)
lt((x1 + x2) / 2, (y1 + y2) / 2);
else
rt((x1 + x2) / 2, (y1 + y2) / 2+1);
}
else
{
if ((y1 + y2) / 2 >= py)
lb((x1 + x2) / 2+1, (y1 + y2) / 2);
else
rb((x1 + x2) / 2+1, (y1 + y2) / 2+1);
}
work(x1, y1, (x1 + x2) / 2, (y1 + y2) / 2, kk - 1);
work(x1, (y1 + y2) / 2+1, (x1 + x2) / 2, y2, kk - 1);
work((x1 + x2) / 2 + 1, y1, x2, (y1 + y2) / 2, kk - 1);
work((x1 + x2) / 2 + 1, (y1 + y2) / 2 + 1, x2, y2, kk - 1);
}
int main()
{
while (cin >> k >> y >> x)
{
memset(chess, 0, sizeof(chess));
chess[x][y] = 7;
tmp = pow(2, k);
work(1,1,tmp,tmp,k);
for (int i = 1; i <= tmp; i++)
{
int j;
for (j = 1; j < tmp; j++)
printf("%d ", chess[i][j]);
printf("%d
", chess[i][j]);
}
}
return 0;
}