C. Harmony Analysis
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 test(s)
input
2
output
++**
+*+*
++++
+**+
Note

Consider all scalar products in example:

  • Vectors 1 and 2: ( + 1)·( + 1) + ( + 1)·( - 1) + ( - 1)·( + 1) + ( - 1)·( - 1) = 0
  • Vectors 1 and 3: ( + 1)·( + 1) + ( + 1)·( + 1) + ( - 1)·( + 1) + ( - 1)·( + 1) = 0
  • Vectors 1 and 4: ( + 1)·( + 1) + ( + 1)·( - 1) + ( - 1)·( - 1) + ( - 1)·( + 1) = 0
  • Vectors 2 and 3: ( + 1)·( + 1) + ( - 1)·( + 1) + ( + 1)·( + 1) + ( - 1)·( + 1) = 0
  • Vectors 2 and 4: ( + 1)·( + 1) + ( - 1)·( - 1) + ( + 1)·( - 1) + ( - 1)·( + 1) = 0
  • Vectors 3 and 4: ( + 1)·( + 1) + ( + 1)·( - 1) + ( + 1)·( - 1) + ( + 1)·( + 1) = 0

题目链接:点击打开链接

在2^k维空间中构造2^k个相互垂直的向量.

观察给出的数据, 无限脑洞...

AC代码:

#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
#include "queue"
#include "stack"
#include "cmath"
#include "utility"
#include "map"
#include "set"
#include "vector"
#include "list"
#include "string"
#include "cstdlib"
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
int n;
int main(int argc, char const *argv[])
{
scanf("%d", &n);
n = 1 << n;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j)
printf("%c", __builtin_parity(i & j) ? '*' : '+');
printf("\n");
}
return 0;
}

列举四个位运算函数:

  • int __builtin_ffs (unsigned int x)

    返回x的最后一位1的是从后向前第几位,比方7368(1110011001000)返回4。
  • int __builtin_clz (unsigned int x)

    返回前导的0的个数。

  • int __builtin_ctz (unsigned int x)

    返回后面的0个个数,和__builtin_clz相对。

  • int __builtin_popcount (unsigned int x)

    返回二进制表示中1的个数。

  • int __builtin_parity (unsigned int x)

    返回x的奇偶校验位,也就是x的1的个数模2的结果。
  • 摘自:点击打开链接

Codeforces Round #337 (Div. 2) 610C Harmony Analysis(脑洞)的更多相关文章

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

    C. Harmony Analysis 题目连接: http://www.codeforces.com/contest/610/problem/C Description The semester i ...

  2. Codeforces Round #337 (Div. 2) C. Harmony Analysis 数学

    C. Harmony Analysis   The semester is already ending, so Danil made an effort and decided to visit a ...

  3. Codeforces Round #337 (Div. 2) C. Harmony Analysis

    题目链接:http://codeforces.com/contest/610/problem/C 解题思路: 将后一个矩阵拆分为四个前一状态矩阵,其中三个与前一状态相同,剩下一个直接取反就行.还有很多 ...

  4. Codeforces Round #337 (Div. 2)

    水 A - Pasha and Stick #include <bits/stdc++.h> using namespace std; typedef long long ll; cons ...

  5. Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树扫描线

    D. Vika and Segments 题目连接: http://www.codeforces.com/contest/610/problem/D Description Vika has an i ...

  6. Codeforces Round #337 (Div. 2) B. Vika and Squares 贪心

    B. Vika and Squares 题目连接: http://www.codeforces.com/contest/610/problem/B Description Vika has n jar ...

  7. Codeforces Round #337 (Div. 2) A. Pasha and Stick 数学

    A. Pasha and Stick 题目连接: http://www.codeforces.com/contest/610/problem/A Description Pasha has a woo ...

  8. Codeforces Round #337 (Div. 2) D. Vika and Segments (线段树+扫描线+离散化)

    题目链接:http://codeforces.com/contest/610/problem/D 就是给你宽度为1的n个线段,然你求总共有多少单位的长度. 相当于用线段树求面积并,只不过宽为1,注意y ...

  9. Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树 矩阵面积并

    D. Vika and Segments     Vika has an infinite sheet of squared paper. Initially all squares are whit ...

随机推荐

  1. Vue-cli 3.0 构建项目

    Vue-cli是vue的一个脚手架,我们可以通过它来构建我们的前端项目 vue-cli3环境配置 //1. 安装nodeJS(已经集成npm) 首先需要安装node环境,可以直接到中文官网http:/ ...

  2. C语言传参的类型匹配

    有一个这样的问题: 形参const char *p和实参char *c可以匹配 形参const char**p和实参char**c不可以匹配 注:argument和parameter:严格而言,par ...

  3. LAMP环境搭建备忘 -- Apache、pHp 安装 (二)

    上一篇 Linux 已经安装好了,我们选择了 CentOS 7 的最小化安装,即没有图形界面,并且我们在安装时设置了网络连接即能够连上外部网络,还设置了 root 密码.下面我们要在此基础上继续安装 ...

  4. 越努力越幸运--2-LD_PRELOAD, fork ,僵尸进程

    开始新的工作了,做了爸爸之后感觉一直都是浑浑噩噩,希望老婆和宝宝一直健康开心~ 最近遇到的问题很多啊,哈哈 1. 装环境时候,需要的glibc 版本不对,我把本地的软链接改了个别名(惯性思维),然后一 ...

  5. win10 64位下VirtualBox安装CentOS6.9

    第一步:安装VritualBox 百度“VritualBox”下载安装即可: 第二步:下载Linux镜像系统并安装 这里写出我参照的博客,很详细,我就不累赘了! 原文地址:http://blog.cs ...

  6. HNU 13108 Just Another Knapsack Problem DP + Trie树优化

    题意: 给你一个文本串,和一些模式串,每个模式串都有一个价值,让你选一些模式串来组成文本串,使获得的价值最大.每个模式串不止能用一次. 思路: 多重背包,枚举文本串的每个位置和模式串,把该模式串拼接在 ...

  7. 2015 Multi-University Training Contest 4 hdu 5336 XYZ and Drops

    XYZ and Drops Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  8. swift入门-实现简单的登录界面

    // // AppDelegate.swift // UIWindow import UIKit @UIApplicationMain class AppDelegate: UIResponder, ...

  9. Seq和Ack

    http://blog.csdn.net/bytebai/article/details/21752925 握手阶段: 序号    方向         seq           ack1  A-& ...

  10. Find or Query Data with the mongo Shell

    https://docs.mongodb.com/getting-started/shell/query/ Overview You can use the find() method to issu ...