UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#196160#1249. 神奇的幻方(基础版)xuziheng1000ms1224kbC++419b2023-10-19 10:09:442023-10-19 10:09:47

answer

#include<bits/stdc++.h>
using namespace std;
int n,a[50][50];
int main()
{
	cin>>n;n=n*2-1;int x=1,i=1,j=n/2+1;a[i][j]=x;
	while(x!=n*n)
	{
		x++;
		if(a[i-1][j+1]) i++;
		  else i--,j++;
		if(i<1&&j>n)
		{
			i=2;j=n;
		}
		if(i<1) i=n;
		if(j>n) j=1;
		a[i][j]=x;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++) printf("%3d ",a[i][j]);
		cout<<endl; 
	}
	   
	cout<<endl; 
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 20
Accepted
time: 0ms
memory: 1224kb

input:

19

output:

705 744 783 822 861 900 939 978 1017 1056 1095 1134 1173 1212 1251 1290 1329 1368   1  40  79 118 15...

result:

ok 37 lines

Test #2:

score: 20
Accepted
time: 0ms
memory: 1224kb

input:

3

output:

 17  24   1   8  15 
 23   5   7  14  16 
  4   6  13  20  22 
 10  12  19  21   3 
 11  18  25   2 ...

result:

ok 5 lines

Test #3:

score: 20
Accepted
time: 0ms
memory: 1220kb

input:

6

output:

 68  81  94 107 120   1  14  27  40  53  66 
 80  93 106 119  11  13  26  39  52  65  67 
 92 105 11...

result:

ok 11 lines

Test #4:

score: 20
Accepted
time: 0ms
memory: 1224kb

input:

8

output:

122 139 156 173 190 207 224   1  18  35  52  69  86 103 120 
138 155 172 189 206 223  15  17  34  51...

result:

ok 15 lines

Test #5:

score: 20
Accepted
time: 0ms
memory: 1224kb

input:

10

output:

192 213 234 255 276 297 318 339 360   1  22  43  64  85 106 127 148 169 190 
212 233 254 275 296 317...

result:

ok 19 lines