zoukankan      html  css  js  c++  java
  • 2019暑假牛客多校训练-第八场-C-CDMA(递归、水题)

    观察前3组可以推出递归规律,生成下一个类型时,每行copy自身与自身相反。

    题目描述 

    Gromah and LZR have entered the third level. There is a blank grid of size m imes 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 imes 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.

    输入描述:

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

    输出描述:

    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.
    示例1

    输入

    复制
    2

    输出

    复制
    1 1
    1 -1

    说明

    The inner product of the two rows is 1	imes(-1) + 1	imes 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
    ";
    14         cout<<"1 -1
    ";
    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<<'
    ';
    41     }
    42 }
    
    
    


  • 相关阅读:
    vue自定义指令
    ZOJ Problem Set–2104 Let the Balloon Rise
    ZOJ Problem Set 3202 Secondprice Auction
    ZOJ Problem Set–1879 Jolly Jumpers
    ZOJ Problem Set–2405 Specialized FourDigit Numbers
    ZOJ Problem Set–1874 Primary Arithmetic
    ZOJ Problem Set–1970 All in All
    ZOJ Problem Set–1828 Fibonacci Numbers
    要怎么样调整状态呢
    ZOJ Problem Set–1951 Goldbach's Conjecture
  • 原文地址:https://www.cnblogs.com/Never-Land/p/11334524.html
Copyright © 2011-2022 走看看