#include <stdio.h>
#define N 102
void pp(int a[][N], int n)
{
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= n ; ++j)
{
if (a[i][j])
}
}
}
int main()
{
int n, sideLength;
int a[N][N];
for (sideLength = 0; sideLength * sideLength < n; ++sideLength);
// initialize
for (int i = 0; i <= sideLength + 1; ++i)
for (int j = 0; j <= sideLength + 1; ++j)
{
a[i][j] = 0;
if (i == 0 || j == 0 || i == sideLength + 1 || j == sideLength + 1 )
a[i][j] = -1;
}
int x = 1, y = 1, dx = 1, dy = 0;
for (int i = 1; i <= n; ++i)
{
a[y][x] = i;
if (a[y + dy][x + dx])
{
// change direction
int t = -dy;
dy = dx;
dx = t;
}
x += dx;
y += dy;
}
pp(a, sideLength);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNkZWZpbmUgTiAxMDIKdm9pZCBwcChpbnQgYVtdW05dLCBpbnQgbikKewogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgKytpKQogICAgewogICAgICAgIGZvciAoaW50IGogPSAxOyBqIDw9IG4gOyArK2opCiAgICAgICAgewogICAgICAgICAgICBpZiAoYVtpXVtqXSkKICAgICAgICAgICAgICAgIHByaW50ZigiJTVkIiAsIGFbaV1bal0pOwogICAgICAgICAgICBlbHNlIHByaW50ZigiJTVzIiwgIiIpOwogICAgICAgIH0KICAgICAgICBwdXRjaGFyKCdcbicpOwogICAgfQp9CmludCBtYWluKCkKewogICAgaW50IG4sIHNpZGVMZW5ndGg7CiAgICBpbnQgYVtOXVtOXTsKICAgIHByaW50Zigibigxfjk5OTkpID0gIik7CiAgICBzY2FuZigiJWQiLCAmbik7CiAgICBmb3IgKHNpZGVMZW5ndGggPSAwOyBzaWRlTGVuZ3RoICogc2lkZUxlbmd0aCA8IG47ICsrc2lkZUxlbmd0aCk7CiAgICAvLyBpbml0aWFsaXplCiAgICBmb3IgKGludCBpID0gMDsgaSA8PSBzaWRlTGVuZ3RoICsgMTsgKytpKQogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDw9IHNpZGVMZW5ndGggKyAxOyArK2opCiAgICAgICAgewogICAgICAgICAgICBhW2ldW2pdID0gMDsKICAgICAgICAgICAgaWYgKGkgPT0gMCB8fCBqID09IDAgfHwgaSA9PSBzaWRlTGVuZ3RoICsgMSB8fCBqID09IHNpZGVMZW5ndGggKyAxICkKICAgICAgICAgICAgICAgIGFbaV1bal0gPSAtMTsKICAgICAgICB9CiAgICBpbnQgeCA9IDEsIHkgPSAxLCBkeCA9IDEsIGR5ID0gMDsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47ICsraSkKICAgIHsKICAgICAgICBhW3ldW3hdID0gaTsKICAgICAgICBpZiAoYVt5ICsgZHldW3ggKyBkeF0pCiAgICAgICAgewogICAgICAgICAgICAvLyBjaGFuZ2UgZGlyZWN0aW9uCiAgICAgICAgICAgIGludCB0ID0gLWR5OwogICAgICAgICAgICBkeSA9IGR4OwogICAgICAgICAgICBkeCA9IHQ7CiAgICAgICAgfQogICAgICAgIHggKz0gZHg7CiAgICAgICAgeSArPSBkeTsKICAgIH0KICAgIHBwKGEsIHNpZGVMZW5ndGgpOwoKICAgIHJldHVybiAwOwp9Cg==