Codeforces Round #337 (Div. 2)-C Harmony Analysis(构造x维正交向量)

来源:互联网 发布:美国历年宏观经济数据 编辑:程序博客网 时间:2024/05/16 01:35
C. Harmony Analysis
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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?

Input

The only line of the input contains a single integer k (0 ≤ k ≤ 9).

Output

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.

Examples
input
2
output
++**+*+*+++++**+
Note

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个两两相交的正交向量。

题解:观察规律,当k=1时,情况可以是
++
+-
当k=2时
++++
+-+-
++--
+--+
可以发现,是将这n维矩阵分成4块,左上、右上、左下相同,右下相反。。
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int a[1520][1520];int main(void){int i,j,k,n;scanf("%d",&n);a[0][0]=1;for(k=1;k<=n;k++)for(i=0;i<(1<<(k-1));i++)for(j=0;j<(1<<(k-1));j++){a[i][j+(1<<(k-1))]=a[i][j];a[i+(1<<(k-1))][j]=a[i][j];a[i+(1<<(k-1))][j+(1<<(k-1))]=1-a[i][j];}for(i=0;i<(1<<n);i++){for(j=0;j<(1<<n);j++){if(a[i][j])printf("+");elseprintf("*");}printf("\n");}return 0;}


阅读全文
0 0
原创粉丝点击