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

题目描述

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_i∑i=1n​si​ti​.
 
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.

输入描述:

Only one positive integer m_{}m​ in one line.
 
m \in \{2^k \; | \;k = 1, 2, \cdots, 10\}m∈{2k∣k=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\times(-1) + 1\times 1 = 01×(−1)+1×1=0.

代码如下
 #include <iostream>
#include <math.h>
using namespace std;
char a[][];
int main(){
int n,m,aa();
a[][]='';
a[][]='';
a[][]='';
a[][]='';
cin>>n;
if(n==){
cout<<"1 1\n";
cout<<"1 -1\n";
return ;
}
m=log2(n)-;
while(m--){
aa=aa*;
for(int k=, t=aa;k<aa;k++,t++){
for(int i=,j=aa;j<*aa;j++,i++){
if(a[k][i]=='') {
a[k][j]='';
a[t][i]='';
a[t][j]='';
}
else {
a[k][j]='';
a[t][i]='';
a[t][j]='';
}
}
}
}
for(int i=;i<n;i++){
for(int j=;j<n;j++){
if(a[i][j]=='') cout<<"1 ";
else cout<<"-1 ";
}
cout<<'\n';
}
}



2019暑假牛客多校训练-第八场-C-CDMA(递归、水题)的更多相关文章

  1. 牛客多校训练第八场C.CDMA(思维+构造)

    题目传送门 题意: 输入整数m( m∈2k ∣ k=1,2,⋯,10),构造一个由1和-1组成的m×m矩阵,要求对于任意两个不同的行的内积为0. 题解: Code: #include<bits/ ...

  2. 牛客多校训练第八场G.Gemstones(栈模拟)

    题目传送门 题意: 输入一段字符串,字符串中连续的三个相同的字符可以消去,消去后剩下的左右两段字符串拼接,求最多可消去次数. 输入:ATCCCTTG   输出:2 ATCCCTTG(消去CCC)——& ...

  3. 2019牛客多校训练第四场K.number(思维)

    题目传送门 题意: 输入一个只包含数字的字符串,求出是300的倍数的子串的个数(不同位置的0.00.000等都算,并考虑前导零的情况). sample input: 600 1230003210132 ...

  4. 2019牛客多校训练第三场H.Magic Line(思维)

    题目传送门 大致题意: 输入测试用例个数T,输入点的个数n(n为偶数),再分别输入n个不同的点的坐标,要求输出四个整数x1,y1,x2,y2,表示有一条经过点(x1,y1),(x2,y2)的直线将该二 ...

  5. 2019牛客多校训练第三场B.Crazy Binary String(思维+前缀和)

    题目传送门 大致题意: 输入整数n(1<=n<=100000),再输入由n个0或1组成的字符串,求该字符串中满足1和0个数相等的最长子串.子序列. sample input: 801001 ...

  6. 2019年牛客多校第一场B题Integration 数学

    2019年牛客多校第一场B题 Integration 题意 给出一个公式,求值 思路 明显的化简公式题,公式是分母连乘形式,这个时候要想到拆分,那如何拆分母呢,自然是裂项,此时有很多项裂项,我们不妨从 ...

  7. Cutting Bamboos(2019年牛客多校第九场H题+二分+主席树)

    题目链接 传送门 题意 有\(n\)棵竹子,然后有\(q\)次操作,每次操作给你\(l,r,x,y\),表示对\([l,r]\)区间的竹子砍\(y\)次,每次砍伐的长度和相等(自己定砍伐的高度\(le ...

  8. Distance(2019年牛客多校第八场D题+CDQ+树状数组)

    题目链接 传送门 思路 这个题在\(BZOJ\)上有个二维平面的版本(\(BZOJ2716\)天使玩偶),不过是权限题因此就不附带链接了,我也只是在算法进阶指南上看到过,那个题的写法是\(CDQ\), ...

  9. 2019年牛客多校第四场 B题xor(线段树+线性基交)

    题目链接 传送门 题意 给你\(n\)个基底,求\([l,r]\)内的每个基底是否都能异或出\(x\). 思路 线性基交板子题,但是一直没看懂咋求,先偷一份咖啡鸡板子写篇博客吧~ 线性基交学习博客:传 ...

随机推荐

  1. LeetCode 841. Keys and Rooms

    原题链接在这里:https://leetcode.com/problems/keys-and-rooms/ 题目: There are N rooms and you start in room 0. ...

  2. area标签的使用,图片中某一个部分可以点击跳转,太阳系中点击某个行星查看具体信息

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  3. learning java Charset 查看支持的字符集类型

    import java.nio.charset.Charset; import java.util.SortedMap; public class CharsetTest { public stati ...

  4. Java如何正确的将数值转化为ArrayList?

    Java中使用工具类Arrays.asList()看似可以把一个数组转为List,但实际使用时有两个坑:1.它是泛型方法,传入的参数必须是对象数组,当传入一个原生数据类型数组时,Arrays.asLi ...

  5. struct iphdr

    struct iphdr { #if defined(__LITTLE_ENDIAN_BITFIELD) __u8 ihl:, version:; #elif defined (__BIG_ENDIA ...

  6. manjaro web

    https://wiki.manjaro.org/index.php?title=Main_Page https://forum.manjaro.org/ https://gitlab.manjaro ...

  7. linux定时执行shell脚本

    写一个shell脚本,定时执行简单示例 很多时候我们有希望服务器定时去运行一个脚本来触发一个操作,比如说定时去备份服务器数据.数据库数据等 不适合人工经常做的一些操作这里简单说下 Shell俗称壳,类 ...

  8. 带状矩阵的存储(c++)

    2     1     0     0 3     1     3     0 0     5     2     7 0     0     9     0 这个程序对于三对角矩阵都是有效的,为了精 ...

  9. ICEM-三棱锥的一种画法

    原视频下载地址:https://pan.baidu.com/s/1c4BAqy 密码: nqb4

  10. 【2019.12.11】SDN上机第7次作业

    打开P4的目录,运行主程序 make run 此时输入命令 pingall 会显示所有的网络不通 改为下方代码 /* -*- P4_16 -*- */ #include <core.p4> ...