两两内积为0(牛客多校第七场)-- CDMA

题意:

构造一个n*n的矩阵,元素只能是-1或1,任意两行内积为0(两两相乘加起来和为0)。

思路;

  1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
  2 #include <cstdio>//sprintf islower isupper
  3 #include <cstdlib>//malloc  exit strcat itoa system("cls")
  4 #include <iostream>//pair
  5 #include <fstream>
  6 #include <bitset>
  7 //#include <map>
  8 //#include<unordered_map>
  9 #include <vector>
 10 #include <stack>
 11 #include <set>
 12 #include <string.h>//strstr substr
 13 #include <string>
 14 #include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
 15 #include <cmath>
 16 #include <deque>
 17 #include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
 18 #include <vector>//emplace_back
 19 //#include <math.h>
 20 //#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
 21 #include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
 22 using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
 23 #define fo(a,b,c) for(register int a=b;a<=c;++a)
 24 #define fr(a,b,c) for(register int a=b;a>=c;--a)
 25 #define mem(a,b) memset(a,b,sizeof(a))
 26 #define pr printf
 27 #define sc scanf
 28 #define ls rt<<1
 29 #define rs rt<<1|1
 30 void swapp(int &a,int &b);
 31 double fabss(double a);
 32 int maxx(int a,int b);
 33 int minn(int a,int b);
 34 int Del_bit_1(int n);
 35 int lowbit(int n);
 36 int abss(int a);
 37 //const long long INF=(1LL<<60);
 38 const double E=2.718281828;
 39 const double PI=acos(-1.0);
 40 const int inf=(1<<29);
 41 const double ESP=1e-9;
 42 const int mod=(int)1e9+7;
 43 const int N=(int)1e6+10;
 44  
 45 int mp[1030][1030];
 46  
 47 void same(int cnt)
 48 {
 49     fo(i,1,cnt)
 50     {
 51         fo(j,1,cnt)
 52         {
 53             mp[i][j+cnt]=mp[i][j];
 54         }
 55     }
 56 }
 57  
 58 void _(int cnt)
 59 {
 60     fo(i,cnt+1,cnt*2-1)
 61     {
 62         fo(j,1,cnt)
 63             mp[i][j]=mp[i-cnt+1][j];
 64         fo(j,cnt+1,cnt*2)
 65             mp[i][j]=1-mp[i-cnt+1][j];
 66     }
 67     fo(i,1,cnt)
 68         mp[cnt*2][i]=1;
 69     fo(i,cnt+1,cnt*2)
 70         mp[cnt*2][i]=0;
 71 }
 72  
 73 int main()
 74 {
 75     mp[1][1]=mp[1][2]=mp[2][1]=1;
 76     int cnt=2;
 77     fo(i,2,10)
 78     {
 79         same(cnt);
 80         _(cnt);
 81         cnt*=2;
 82     }
 83     int n;
 84     sc("%d",&n);
 85     fo(i,1,n)
 86         fo(j,1,n)
 87             pr("%d%c",mp[i][j]==1?mp[i][j]:-1,j==n?'\n':' ');
 88     return 0;
 89 }
 90  
 91 /**************************************************************************************/
 92  
 93 int maxx(int a,int b)
 94 {
 95     return a>b?a:b;
 96 }
 97  
 98 void swapp(int &a,int &b)
 99 {
100     a^=b^=a^=b;
101 }
102  
103 int lowbit(int n)
104 {
105     return n&(-n);
106 }
107  
108 int Del_bit_1(int n)
109 {
110     return n&(n-1);
111 }
112  
113 int abss(int a)
114 {
115     return a>0?a:-a;
116 }
117  
118 double fabss(double a)
119 {
120     return a>0?a:-a;
121 }
122  
123 int minn(int a,int b)
124 {
125     return a<b?a:b;
126 }

 

转载于:https://www.cnblogs.com/--HPY-7m/p/11440318.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值