F.A.Qs Home ProblemSet Status Ranklist Contest LoginRegister
大视野在线测评-欢迎您
[ New Thread ]
MainBoard >> sd
XJY0327 @ 2019-07-15 19:20:02
[ Quote ] [ Edit ] [ Delete ] 1#
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 105;

int a[N][N], n, p;

int main() {
// freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
cin >> n;
for (int i = 1; i <= n; i++)
a[i][0] = a[i][n + 1] = a[n + 1][i] = a[0][i] = 1;
int i = n, j = n, p = n * n;

bool flag=1;
for (int fff=1;fff<=1000000;fff++){

while (a[i][j - 1] == 0)
a[i][j] = p--, j--,flag=1;
while (a[i - 1][j] == 0)
a[i][j] = p--,i--,flag=1;
while (a[i][j + 1] == 0)
a[i][j] = p--,j++,flag=1;
while (a[i + 1][j] == 0)
a[i][j] = p--,i++,flag=1;
// if(!flag) break;
}
a[i][j]=1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++)
printf("%d ", a[i][j]);
puts("");
}
return 0;
}
[Top] [Previous Page] [Next Page]

HOME Back