2019 summer cattle off more school training - Session 8 -C-CDMA (recursion, water problems)

When the three groups can be introduced before observation recursive law, the next generation type, each with its own row opposite to copy itself.

Title Description 

Gromah and LZR have entered the third level. There is a blank grid of size  m\times mm×m, and above the grid is a word "CDMA".
 
In CDMA Technology, a Technology about computer network, every network node should be appointed a unique binary sequence with a fixed and the same length. Moreover, if we regard  0_{}0 in the sequence as -1_{}1, and regard 1_{}1 as +1_{}+1, then these sequences should satisfy that for any two different sequences s,t_{}s,t, the inner product of s,t_{}s,t should be exactly 0_{}0.
 
The inner product of two sequences  s,t_{}s,t with the same length n_{}n equals to \sum_{i=1}^{n} s_it_ii=1nsiti.
 
So, the key to the next level is to construct a grid of size  m\times mm×m, whose elements are all -1_{}1 or 1_{}1, and for any two different rows, the inner product of them should be exactly 0_{}0.
 
In this problem, it is guaranteed that m_{}m is a positive integer power of 2_{}2 and there exists some solutions for input m_{}m. If there are multiple solutions, you may print any of them.

Enter a description:

Only one positive integer m_{}m in one line.
 
m \in \{2^k \; | \;k = 1, 2, \cdots, 10\}m{2kk=1,2,,10}

Output Description:

Print m_{}m lines, each contains a sequence with length m_{}m, whose elements should be all -1_{}1 or 1_{}1 satisfying that for any two different rows, the inner product of them equals 0_{}0.

You may print multiple blank spaces between two numbers or at the end of each line, and you may print any number of blank characters at the end of whole output file.
Example 1

Entry

copy
2

Export

copy
1 1
1 -1

Explanation

The inner product of the two rows is 1\times(-1) + 1\times 1 = 01×(1)+1×1=0.

代码如下
 1 #include <iostream>
 2 #include <math.h>
 3 using namespace std;
 4 char a[1050][1050];
 5 int main(){
 6     int n,m,aa(1);
 7     a[0][0]='1';
 8     a[0][1]='1';
 9     a[1][0]='1';
10     a[1][1]='0';
11     cin>>n;
12     if(n==2){
13         cout<<"1 1\n";
14         cout<<"1 -1\n";
15         return 0;
16     }
17     m=log2(n)-1;
18     while(m--){
19         aa=aa*2;
20         for(int k=0, t=aa;k<aa;k++,t++){
21             for(int i=0,j=aa;j<2*aa;j++,i++){
22                 if(a[k][i]=='1') {
23                     a[k][j]='0';
24                     a[t][i]='1';
25                     a[t][j]='1';
26                 }
27                 else {
28                     a[k][j]='1';
29                     a[t][i]='0';
30                     a[t][j]='0';
31                 }
32             }
33         }
34     }
35     for(int i=0;i<n;i++){
36         for(int j=0;j<n;j++){
37             if(a[i][j]=='1') cout<<"1 ";
38             else cout<<"-1 ";
39         }
40         cout<<'\n';
41     }
42 }
 
     

 



Guess you like

Origin www.cnblogs.com/Never-Land/p/11334524.html