The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vectors in 4-dimensional space, such that every coordinate of every vector is 1 or - 1 and any two vectors are orthogonal. Just as a reminder, two vectors in n-dimensional space are considered to be orthogonal if and only if their scalar product is equal to zero, that is:
Danil quickly managed to come up with the solution for this problem and the teacher noticed that the problem can be solved in a more general case for 2k vectors in 2k-dimensinoal space. When Danil came home, he quickly came up with the solution for this problem. Can you cope with it?
The only line of the input contains a single integer k (0 ≤ k ≤ 9).
Print 2k lines consisting of 2k characters each. The j-th character of the i-th line must be equal to ' * ' if the j-th coordinate of the i-th vector is equal to - 1, and must be equal to ' + ' if it's equal to + 1. It's guaranteed that the answer always exists.
If there are many correct answers, print any.
2
++** +*+* ++++ +**+
Consider all scalar products in example:
- Vectors 1 and 2: ( + 1)·( + 1) + ( + 1)·( - 1) + ( - 1)·( + 1) + ( - 1)·( - 1) = 0
- Vectors 1 and 3: ( + 1)·( + 1) + ( + 1)·( + 1) + ( - 1)·( + 1) + ( - 1)·( + 1) = 0
- Vectors 1 and 4: ( + 1)·( + 1) + ( + 1)·( - 1) + ( - 1)·( - 1) + ( - 1)·( + 1) = 0
- Vectors 2 and 3: ( + 1)·( + 1) + ( - 1)·( + 1) + ( + 1)·( + 1) + ( - 1)·( + 1) = 0
- Vectors 2 and 4: ( + 1)·( + 1) + ( - 1)·( - 1) + ( + 1)·( - 1) + ( - 1)·( + 1) = 0
- Vectors 3 and 4: ( + 1)·( + 1) + ( + 1)·( - 1) + ( + 1)·( - 1) + ( + 1)·( + 1) = 0
假设把当前2 ^ k * (2 ^ k)分成左上,右上,左下,右下四个方阵,假设当前我们已知k - 1时的方阵,只要把左上,左下右上填成与k - 1相同方阵,右下填成
与k - 1方阵反相即可。
1 #include2 #include 3 #include 4 #include 5 #include 6 7 8 using namespace std; 9 10 const int maxn = 520;11 char mar[maxn][maxn];12 int k;13 14 char invert(char x) {15 return x == '+' ? '*' : '+';16 }17 18 int main() {19 scanf("%d", &k);20 mar[0][0] = '+';21 for (int i = 1; i <= k; ++i) {22 int a = pow(2, i - 1);23 int b = pow(2, i);24 for (int r = 0; r < a; ++r) {25 for (int c = a; c < b; ++c) {26 mar[r][c] = mar[r][c - a];27 }28 }29 30 for (int r = a; r < b; ++r) {31 for (int c = 0; c < a; ++c) {32 mar[r][c] = mar[r - a][c];33 }34 }35 36 for (int r = a; r < b; ++r) {37 for (int c = a; c < b; ++c) {38 mar[r][c] = invert(mar[r][c - a]);39 }40 }41 }42 43 int a = pow(2, k);44 for (int i = 0; i < a; ++i) {45 for (int j = 0; j < a; ++j) {46 printf("%c", mar[i][j]);47 }48 printf("\n");49 }50 51 52 return 0;53 }