Codeforces 610C:Harmony Analysis 递归
来源:互联网 发布:java中冒泡排序法代码 编辑:程序博客网 时间:2024/06/04 18:36
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?
The only line of the input contains a single integer k (0 ≤ k ≤ 9).
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.
2
++**+*+*+++++**+
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维的互相叉乘都是0的向量。
如果要求2^k次方个,可以先考虑2^(k-1),将其按照矩形的方式复制四份,然后最后的那一份取反。
证明也很简单,上边没有取反的那部分肯定互相之间是叉乘是0的,因为前半部分叉乘是0,后半部分叉乘也是0。
上下部分,如果是原来的自己取反的,那么前半部分和后半部分的相乘一定是互为相反数的关系。如果不是自己取反的那一个,那就是其它的后半部分取反的,没有影响,还是0。
递归求解。
代码:
#pragma warning(disable:4996)#include <iostream>#include <algorithm>#include <cmath>#include <vector>#include <string>#include <cstring>#include <set>#include <queue>#include <stack>using namespace std;const int maxn = 530;int k;int val[maxn][maxn];void rec(int n, int x, int y, int v){if (n == 1){val[x][y] = v;}else{rec(n / 2, x, y, v);rec(n / 2, x + n / 2, y, v);rec(n / 2, x, y + n / 2, v);rec(n / 2, x + n / 2, y + n / 2, -v);}}void input(){cin >> k;}void solve(){rec(1 << k, 1, 1, 1);int i, j;for (i = 1; i <= (1 << k); i++){for (j = 1; j <= (1 << k); j++){if (val[i][j] == 1){cout << "+";}else{cout << "*";}}cout << endl;}}int main(){//freopen("i.txt","r",stdin);//freopen("o.txt","w",stdout);input();solve();//system("pause");return 0;}
- Codeforces 610C:Harmony Analysis 递归
- codeforces 610C Harmony Analysis 构造
- CodeForces 610 C. Harmony Analysis(构造)
- Codeforces 610C Harmony Analysis(构造)
- 【53.57%】【codeforces 610C】Harmony Analysis
- 610C Harmony Analysis
- CodeForces 610 B - Harmony Analysis
- Codeforces Round #337 (Div. 2) 610C Harmony Analysis(脑洞)
- Codeforces 610C Harmony Analysis 【神奇的题目】
- Harmony Analysis CodeForces
- Codeforce 题目337 C. Harmony Analysis(递归)
- Codeforces Round #337 (Div. 2) C Harmony Analysis
- *Codeforces Round #337 (Div. 2) C Harmony Analysis 构造题
- Codeforces - 337C(div2) - Harmony Analysis(找规律)
- Codeforces Round #337 (Div. 2) C Harmony Analysis
- Codeforces Round #337 (Div. 2) C. Harmony Analysis (构造)
- Codeforces Round #337 (Div. 2)C. Harmony Analysis
- Codeforces #337 (Div.2)C.Harmony Analysis【构造】
- 蓝桥杯 区间k大数查询(排序+查找)
- 传播智客J2EE学习线路图
- linux下安装PHP扩展pdo_mysql
- C++ 头文件使用指南
- Codeforces Round #337 (Div. 2) ABCDE
- Codeforces 610C:Harmony Analysis 递归
- 计量经济学复习笔记(1)
- 文本压缩
- 获取Web项目路径
- Android 快速开发系列 打造万能的ListView GridView 适配器
- iOS UITableView(三) 为tableView添加图片实现电话薄
- 【CURL】PHP的CURL开发项目最佳实践
- Java反射学习笔记
- Android程序设计开发范例