zoukankan      html  css  js  c++  java
  • codeforce610C. Harmony Analysi

    Codeforces Tutorial

    C. Harmony Analysis

    Problem Analysis

    题目大意生成一个维度为2的k次方的方阵,使得任意两行的内积为0.
    (k=2)

    [left[ egin{array}{cc|cc} 1 & 1 & 1 & 1 \ 1 & -1 & 1 & -1 \ hline 1 & 1 & -1 & -1\ 1 & -1 & -1 & 1\ end{array} ight] ]

    可以发现规律是除了右下角,其他三个矩阵相同,右下角每个元素去相反数。即

    [left[ egin{array}{c|c} A& A\ hline A& -A\ end{array} ight] ]

    可以验证当(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 imes n),然后(n)又是(2)的幂次。突破口往往在这样比较凑巧的特点上。所以题目的形式值得反复推敲

    Reference

  • 相关阅读:
    LeetCode 2 -- Add Two Numbers
    LeetCode 1 -- Two Sum
    LeetCode189——Rotate Array
    Win10下IIS配置 C#项目的部署与发布
    Linux查看进程和删除进程
    使用 Visual Studio 将 ASP.NET Core 应用发布到 Linux 上的应用服务
    Spring Boot 设置启动时路径和端口号
    Linux平台部署.net Core SDK
    C#教程之如何在centos操作系统上发布.net core的项目
    Linux如何查看和控制进程
  • 原文地址:https://www.cnblogs.com/MalcolmMeng/p/10957717.html
Copyright © 2011-2022 走看看