P14370 [GeeksforGeeks] Form coils in a matrix4726
普及
题目描述

Given a positive integer n that represents dimensions of a 4n x 4n matrix with values from 1 to 4n4*n filled from left to right and top to bottom. Your task is to form two coils from matrix and print the coils.
Follow the given examples for better understanding.

Example 1:
Input:
n = 1
Output:
10 6 2 3 4 8 12 16
7 11 15 14 13 9 5 1
Explanation:
The matrix is
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
So, the two coils are as given in the Ouput.
Example 2:
Input:
n = 2
Output:
36 28 20 21 22 30 38 46
54 53 52 51 50 42 34 26
18 10 2 3 4 5 6 7 8
16 24 32 40 48 56 64
29 37 45 44 43 35 27 19
11 12 13 14 15 23 31 39
47 55 63 62 61 60 59 58
57 49 41 33 25 17 9 1
Explanation:
Your Task:
You don't need to read input or print anything. Your task is to complete the function formCoils() which takes an Integer n as input and returns a vector of two vectors representing coil1 and coil2.

Expected Time Complexity: O(n^{2})
Expected Auxiliary Space: O(n^{2})

Constraints:
1 <= n <= 20

输入格式

见题面

输出格式

见题面

样例输入
n = 1
样例输出
10 6 2 3 4 8 12 16 7 11 15 14 13 9 5 1