列表

详情


NC51606. CDMA

描述

Gromah and LZR have entered the third level. There is a blank grid of size , 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 in the sequence as , and regard as , then these sequences should satisfy that for any two different sequences , the inner product of  should be exactly .

The inner product of two sequences  with the same length  equals to .

So, the key to the next level is to construct a grid of size , whose elements are all or , and for any two different rows, the inner product of them should be exactly .

In this problem, it is guaranteed that  is a positive integer power of and there exists some solutions for input . If there are multiple solutions, you may print any of them.

输入描述

Only one positive integer in one line.


输出描述

Print  lines, each contains a sequence with length , whose elements should be all  or  satisfying that for any two different rows, the inner product of them equals .

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 = 0.

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 131ms, 内存消耗: 7008K, 提交时间: 2019-08-10 20:11:28

#include<bits/stdc++.h>
using namespace std;
int a[1025][1025]; 
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++)
	for(int j=0;j<n;j++){
		int x =__builtin_popcount(i&j);
		a[i][j]=x&1? -1:1;
		printf("%d%c",a[i][j]," \n"[j==n-1]);
	}
} 

C++(clang++ 11.0.1) 解法, 执行用时: 46ms, 内存消耗: 2952K, 提交时间: 2022-10-06 15:58:45

#include<bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
using namespace std;
int n;
int main(){
	cin>>n;
	f(i,n){
		f(j,n)
			if(__builtin_popcount(i&j)&1)cout<<"-1 ";
			else cout<<"1 ";
        cout<<endl;
	}
}

上一题