codeforce610C. Harmony Analysi

Posted malcolmmeng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codeforce610C. Harmony Analysi相关的知识,希望对你有一定的参考价值。

Codeforces Tutorial

C. Harmony Analysis

Problem Analysis

题目大意生成一个维度为2的k次方的方阵,使得任意两行的内积为0.
\(k=2\)
\[ \left[ \beginarraycc|cc 1 & 1 & 1 & 1 \ 1 & -1 & 1 & -1 \ \hline 1 & 1 & -1 & -1\ 1 & -1 & -1 & 1\ \endarray\right] \]

可以发现规律是除了右下角,其他三个矩阵相同,右下角每个元素去相反数。即
\[ \left[ \beginarrayc|c A& A\\hline A& -A\\endarray \right] \]

可以验证当\(k=1\)时也成立。

Acepted Code

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<istream>
#include<cassert>
#include<set>
#define DEBUG(x) cout<<#x<<" = "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<endl
using namespace std;
typedef long long ll;
const int MAXN=600;
int power2(int n)

    int rt=1;
    for(int ii=1;ii<=n ;ii++ )
        rt*=2;
    
    return rt;

int grid[MAXN][MAXN];
void format(int n)

    if(n==1)cout<<"+";
    else cout<<"*";

int main()

//    freopen("in.txt","r",stdin);
    int k;
    cin>>k;
    grid[1][1]=1;
    for(int ii=1;ii<=k ;ii++ )
        ///对称生长法
        int l=power2(ii-1)+1,r=power2(ii),
        delta=l-1;
        for(int row=l-delta;row<=r-delta ;row++ )
            for(int col=l;col<=r ;col++ )
                grid[row][col]=grid[row][col-delta];
            
        
        for(int row=l;row<=r ;row++ )
            for(int col=l-delta;col<=r-delta ;col++ )
                grid[row][col]=grid[row-delta][col];
            
        
        for(int row=l;row<=r ;row++ )
            for(int col=l;col<=r ;col++ )
                grid[row][col]=-grid[row-delta][col-delta];
            
        
    
    int pw=power2(k);
    for(int ii=1;ii<=pw ;ii++ )
        for(int jj=1;jj<=pw ;jj++ )
            format(grid[ii][jj]);
        
        cout<<endl;
    

Wrong Answer Cases

What I Learn

给出的矩阵是\(n\times n\),然后\(n\)又是\(2\)的幂次。突破口往往在这样比较凑巧的特点上。所以题目的形式值得反复推敲

Reference

以上是关于codeforce610C. Harmony Analysi的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces 610C:Harmony Analysis(构造)

Codeforces Round #610 (Div. 2) a/b/c

Codeforces Round #610 (Div. 2)

Codeforces Round #610 (Div. 2) 题解

Codeforces610b

CodeForces 610D Vika and Segments