• 两两内积为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?'
    ':' ');
     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 }
  • 相关阅读:
    (转载)PagerView实现翻页效果
    仿腾讯QQ的紫色下拉折叠菜单代码
    很漂亮的蓝色经典CSS导航菜单代码
    纯CSS实现简约大方灰紫色下拉菜单代码
    鼠标停留在菜单上会闪烁的导航菜单代码
    停在网页顶部可关闭的工具条代码
    JavaScript浮动的导航菜单代码
    深蓝渐变下拉菜单代码
    红色小方块单击爆炸式展开的菜单代码
    很漂亮的蓝色半透明水平下拉导航代码
  • 原文地址:https://www.cnblogs.com/--HPY-7m/p/11440318.html
Copyright © 2020-2023  润新知