F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

奇数阶魔方(II)

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 913    Accepted Submission(s): 585


Problem Description
1 ,2, 3, …,n^2 这n^2 个数 排成n*n 方阵 每行每列每条对角线上的n个数字之和s相等,
s=n(n*n+1)/2,奇数阶魔方可由菱形转变成
n=3,5时如下
3
*********1
******4******2
***7*****5******3
******8******6
*********9
4 9 2
3 5 7
8 1 6
5
*******************1
***************6*******2
**********11*******7*******3
******16*******12*******8*******4
**21******17******13*******9*******5
******22*******18*****14******10
**********23*******19******15
**************24******20
******************25
11 24 7 20 3
4 12 25 8 16
17 5 13 21 9
10 18 1 14 22
23 6 19 2 15
 

Input
输入奇数 3<=n<=21. n=0退出
 

Output
输出n阶魔方,每个数字占4列,右对齐
 

Sample Input
7 0
 

Sample Output
22 47 16 41 10 35 4 5 23 48 17 42 11 29 30 6 24 49 18 36 12 13 31 7 25 43 19 37 38 14 32 1 26 44 20 21 39 8 33 2 27 45 46 15 40 9 34 3 28
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-25 22:07:35, Gzip enabled