• Codeforces Round #337 (Div. 2) C. Harmony Analysis 构造


    C. Harmony Analysis

    题目连接:

    http://www.codeforces.com/contest/610/problem/C

    Description

    The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vectors in 4-dimensional space, such that every coordinate of every vector is 1 or  - 1 and any two vectors are orthogonal. Just as a reminder, two vectors in n-dimensional space are considered to be orthogonal if and only if their scalar product is equal to zero, that is:

    Danil quickly managed to come up with the solution for this problem and the teacher noticed that the problem can be solved in a more general case for 2k vectors in 2k-dimensinoal space. When Danil came home, he quickly came up with the solution for this problem. Can you cope with it?

    Input

    The only line of the input contains a single integer k (0 ≤ k ≤ 9).

    Output

    Print 2k lines consisting of 2k characters each. The j-th character of the i-th line must be equal to ' * ' if the j-th coordinate of the i-th vector is equal to  - 1, and must be equal to ' + ' if it's equal to  + 1. It's guaranteed that the answer always exists.

    If there are many correct answers, print any.

    Sample Input

    2

    Sample Output

    ++**

    ++

    ++++

    +**+

    Hint

    题意

    要求你构造出2^n个2^n维向量,使得向量之间两两相乘都等于0

    题解:

    瞎构造的。。。

    大概证明可以由数学归纳法证明

    假设我现在已经构造出了

    a

    那么我就可以构造出

    a a

    a -a

    然后一直重复就好了。。。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    int dp[1200][1200];
    int n;
    int main()
    {
        scanf("%d",&n);
        dp[0][0]=1;
        for(int x=1;x<=n;x++)
        {
            for(int i=0;i<(1<<x-1);i++)
            {
                for(int j=0;j<(1<<x-1);j++)
                {
                    dp[i][j+(1<<x-1)]=dp[i][j];
                    dp[i+(1<<x-1)][j]=dp[i][j];
                    dp[i+(1<<x-1)][j+(1<<x-1)]=1-dp[i][j];
                }
            }
        }
        for(int i=0;i<(1<<n);i++)
        {
            for(int j=0;j<(1<<n);j++)
            {
                if(dp[i][j])printf("+");
                else printf("*");
            }
            printf("
    ");
        }
        return 0;
    }
  • 相关阅读:
    Selenium快速入门(下)
    Selenium快速入门(上)
    Python中yield和yield from的用法
    Python多进程
    Spring Cloud微服务安全实战_3-5_API安全之常见问题
    Spring Cloud微服务安全实战_3-3_API安全之流控
    Spring Cloud微服务安全实战_3-2_第一个API及注入攻击防护
    Spring Cloud微服务安全实战_3-1_API安全 常见的安全机制
    Spring Cloud微服务安全实战_2-1_开发环境
    Spring Cloud微服务安全实战_1-1_导学
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5081928.html
Copyright © 2020-2023  润新知