超时就打表
by wbhqm @ 2023-09-23 11:24:36
您太强了
by nasasun @ 2023-10-18 16:12:39
@[wbhqm](/user/728909) 哈哈哈哈哈哈
by 17345044098pr @ 2023-11-20 16:28:03
@[17345044098pr](/user/1129224) 笑什么,多好的方法
by wbhqm @ 2023-11-21 16:54:48
@[nasasun](/user/982460)
```
#include<iostream>
#include<iomanip>//fixed,setprecision
#include<math.h>
#include<algorithm>
#include<string>
#include<stdio.h>
using namespace std;
int main()
{
int n;
cin>>n;
if(n==1)
{
cout<<" 1";
}
else if(n==2)
{
cout<<" 1 2"<<endl;
cout<<" 4 3";
}
else if(n==3)
{
cout<<" 1 2 3"<<endl;
cout<<" 8 9 4"<<endl;
cout<<" 7 6 5"<<endl;
}
else if(n==4)
{
cout<<" 1 2 3 4"<<endl;
cout<<" 12 13 14 5"<<endl;
cout<<" 11 16 15 6"<<endl;
cout<<" 10 9 8 7"<<endl;
}
else if(n==5)
{
cout<<" 1 2 3 4 5"<<endl;
cout<<" 16 17 18 19 6"<<endl;
cout<<" 15 24 25 20 7"<<endl;
cout<<" 14 23 22 21 8"<<endl;
cout<<" 13 12 11 10 9"<<endl;
}
else if(n==6)
{
cout<<" 1 2 3 4 5 6"<<endl;
cout<<" 20 21 22 23 24 7"<<endl;
cout<<" 19 32 33 34 25 8"<<endl;
cout<<" 18 31 36 35 26 9"<<endl;
cout<<" 17 30 29 28 27 10"<<endl;
cout<<" 16 15 14 13 12 11"<<endl;
}
else if(n==7)
{
cout<<" 1 2 3 4 5 6 7"<<endl;
cout<<" 24 25 26 27 28 29 8"<<endl;
cout<<" 23 40 41 42 43 30 9"<<endl;
cout<<" 22 39 48 49 44 31 10"<<endl;
cout<<" 21 38 47 46 45 32 11"<<endl;
cout<<" 20 37 36 35 34 33 12"<<endl;
cout<<" 19 18 17 16 15 14 13"<<endl;
}
else if(n==8)
{
cout<<" 1 2 3 4 5 6 7 8"<<endl;
cout<<" 28 29 30 31 32 33 34 9"<<endl;
cout<<" 27 48 49 50 51 52 35 10"<<endl;
cout<<" 26 47 60 61 62 53 36 11"<<endl;
cout<<" 25 46 59 64 63 54 37 12"<<endl;
cout<<" 24 45 58 57 56 55 38 13"<<endl;
cout<<" 23 44 43 42 41 40 39 14"<<endl;
cout<<" 22 21 20 19 18 17 16 15"<<endl;
}
else
{
cout<<" 1 2 3 4 5 6 7 8 9"<<endl;
cout<<" 32 33 34 35 36 37 38 39 10"<<endl;
cout<<" 31 56 57 58 59 60 61 40 11"<<endl;
cout<<" 30 55 72 73 74 75 62 41 12"<<endl;
cout<<" 29 54 71 80 81 76 63 42 13"<<endl;
cout<<" 28 53 70 79 78 77 64 43 14"<<endl;
cout<<" 27 52 69 68 67 66 65 44 15"<<endl;
cout<<" 26 51 50 49 48 47 46 45 16"<<endl;
cout<<" 25 24 23 22 21 20 19 18 17"<<endl;
}
}
```
by wbhqm @ 2023-11-21 16:55:35
@[Longgege114514](/user/1069315) 我来
```c
#include <stdio.h>
int a[10][10], n, num = 1;
int i = 1, j = 1, di = 1;
void f()
{
a[i][j] = num++;
if (di == 1)
{
j++;
if (j > n || a[i][j] > 0)
j--, i++, di = 2;
}
else if (di == 2)
{
i++;
if (i > n || a[i][j] > 0)
i--, j--, di = 3;
}
else if (di == 3)
{
j--;
if (j < 1 || a[i][j] > 0)
i--, j++, di = 4;
}
else
{
i--;
if (a[i][j] > 0)
di=1,i++,j++;
}
}
int main()
{
scanf("%d", &n);
for (int k = 1; k <= n * n; k++)
{
f();
}
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
printf("%3d", a[i][j]);
printf("\n");
}
return 0;
}
```
by gitmeetcat @ 2024-01-23 16:51:20