2019牛客暑期多校训练营(第八场) C CDMA 构造

链接:https://ac.nowcoder.com/acm/contest/888/C
来源:牛客网
 

CDMA

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 524288K,其他语言1048576K
Special Judge, 64bit IO Format: %lld

题目描述

Gromah and LZR have entered the third level. There is a blank grid of size m×mm\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 00_{}0​ in the sequence as −1-1_{}−1​, and regard 11_{}1​ as +1+1_{}+1​, then these sequences should satisfy that for any two different sequences s,ts,t_{}s,t​, the inner product of s,ts,t_{}s,t​ should be exactly 00_{}0​.

 

The inner product of two sequences s,ts,t_{}s,t​ with the same length nn_{}n​ equals to ∑i=1nsiti\sum_{i=1}^{n} s_it_i∑i=1n​si​ti​.

 

So, the key to the next level is to construct a grid of size m×mm\times mm×m, whose elements are all −1-1_{}−1​ or 11_{}1​, and for any two different rows, the inner product of them should be exactly 00_{}0​.

 

In this problem, it is guaranteed that mm_{}m​ is a positive integer power of 22_{}2​ and there exists some solutions for input mm_{}m​. If there are multiple solutions, you may print any of them.

输入描述:

 

Only one positive integer mm_{}m​ in one line.

 

m∈{2k  ∣  k=1,2,⋯ ,10}m \in \{2^k \; | \;k = 1, 2, \cdots, 10\}m∈{2k∣k=1,2,⋯,10}

输出描述:

Print mm_{}m​ lines, each contains a sequence with length mm_{}m​, whose elements should be all −1-1_{}−1​ or 11_{}1​ satisfying that for any two different rows, the inner product of them equals 00_{}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×(−1)+1×1=01\times(-1) + 1\times 1 = 01×(−1)+1×1=0.

题解:对于矩阵 Ai 分成4部分  左上 右上 右下 为 Ai-1  ,左下 为 -Ai-1

#include <bits/stdc++.h>
using namespace std;
int n;
int b[11][1060][1060];
void dfs(int pre, int now) {
    int cnt = (1 << now);
    for(int i = 1; i <= cnt / 2; i++)
        for(int j = 1; j <= cnt / 2; j++)
            b[now][i][j] = b[pre][i][j];
    for(int i = 1; i <= cnt / 2; i++)
        for(int j = cnt / 2 + 1; j <= cnt; j++)
            b[now][i][j] = b[pre][i][j - cnt / 2];
    for(int i = cnt / 2 + 1; i <= cnt; i++)
        for(int j = 1; j <= cnt / 2; j++)
            b[now][i][j] =  - b[pre][i - cnt / 2][j];
    for(int i = cnt / 2 + 1; i <= cnt; i++)
        for(int j = cnt / 2 + 1; j <= cnt; j++)
            b[now][i][j] = b[pre][i - cnt / 2][j - cnt / 2];
}
int main() {
    b[1][1][1] = b[1][1][2] = b[1][2][1] = 1;
    b[1][2][2] = -1;
    for(int i = 2; i <= 10; i++) {
        dfs(i - 1, i);
    }
    int m, cnt;
    while(~scanf("%d", &n)) {
        m = 0;
        cnt = n;
        while(cnt != 1) {
            m++;
            cnt = cnt / 2;
        }
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
                printf("%d%c", b[m][i][j], " \n"[j == n]);
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值