'commit'
This commit is contained in:
34
TangDou/LuoGuBook/P2615.cpp
Normal file
34
TangDou/LuoGuBook/P2615.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 40;
|
||||
int n;
|
||||
int g[N][N];
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
int r = 1;
|
||||
int c = n / 2 + 1;
|
||||
g[r][c] = 1;
|
||||
|
||||
for (int i = 2; i <= n * n; i++) {
|
||||
if (r == 1 && c != n)
|
||||
r = n, c++;
|
||||
else if (c == n && r != 1)
|
||||
r--, c = 1;
|
||||
else if (r == 1 && c == n)
|
||||
r = 2;
|
||||
else if (r != 1 && c != n) {
|
||||
if (g[r - 1][c + 1] == 0)
|
||||
r--, c++;
|
||||
else
|
||||
r++;
|
||||
}
|
||||
g[r][c] = i;
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++, puts(""))
|
||||
for (int j = 1; j <= n; j++)
|
||||
printf("%d ", g[i][j]);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user