题目描述
blablabla
样例
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
int N;
cin >> N;
while(N)
{
int Arr[N][N];
for(int i = 0;i < N;i++)
{
int maxNum;
if(N % 2 == 0)
{
if(i < N/2) maxNum = i + 1;
else if (i == N/2) maxNum = N/2;
else if (i > N/2) maxNum = N - i;
}
else {
if((i+1) == (N+1)/2) maxNum = (N+1)/2;
if((i+1) < (N+1)/2) maxNum = i + 1;
else if ((i+1) > (N+1)/2) maxNum = N - i;
}
for(int k = 0;k < maxNum;k++)
{
Arr[i][k] = k + 1;
Arr[i][N - 1 - k] = k + 1;
}
for(int j = maxNum;j < N - maxNum;j++)
{
Arr[i][j] = maxNum;
}
}
for(int i = 0;i < N;i++)
{
for(int j = 0;j < N;j++)
{
cout << Arr[i][j] << " ";
}
cout << endl;
}
cout << endl;
cin >> N;
}
return 0;
}
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla