NC51606. CDMA
描述
输入描述
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 .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; } }