#include #include #include #include #include #include #include using namespace std; void func(int n, int field[20][20]){ int nextx,nexty; int y,x; y = 0; x = n / 2; field[y][x] = 1; for(int i=2; i<=n*n; i++){ //次へ nextx = (x + 1) % n; nexty = y - 1; if(nexty == -1){ nexty = n - 1; } if(field[nexty][nextx] == 0){ field[nexty][nextx] = i; y = nexty; x = nextx; }else{ y = (y + 1) % n; field[y][x] = i; } } } int main(){ int field[20][20] = {0}; int field2[20][20] = {0}; int n; //3-20 int x,y; int nextx,nexty; bool first[4][4] = {{1,0,0,1},{0,1,1,0},{0,1,1,0},{1,0,0,1}}; int last[20][20] = {0}; //0L 1U 2X int adjust[3][2][2] = {{{4,1},{2,3}}, {{1,4},{2,3}}, {{1,4},{3,2}}}; int i; cin >> n; if(n % 2 == 1){ func(n, field); }else if(n % 4 == 0){ i = 0; for(int iy=0; iy=0; iy--){ for(int ix=n-1; ix>=0; ix--){ i ++; if(!first[iy%4][ix%4]){ field[iy][ix] = i; } } } }else if(n % 4 == 2){ //4n+2 func(n/2, field2); for(int iy=0; iy