Codeforces - 337C(div2) - Harmony Analysis
2016-01-21 17:05
288 查看
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
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
嘿嘿嘿,找规律题,so happy
本来2^9维光想想就要命,根本不知道怎么玩= =虽然多种情况任意输出,但是感觉一种就够我炸了= =
然后自己画了画........0 0?.........0 0!2^1维和2^2维画了几种2333尼玛就是个找规律啊,摔!
规律:答案分成四部分,左上部分 = 右上部分= 左下部分,右下部分跟他们相反(应该也有其他规律,不过懒得看了= =)(我才不说我是靠2^1维2^2维强行猜的规律= =)
求2^(k-1)维扩展到2^k维,所以从2^1维扩展到2^9维,进行预处理
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
嘿嘿嘿,找规律题,so happy
本来2^9维光想想就要命,根本不知道怎么玩= =虽然多种情况任意输出,但是感觉一种就够我炸了= =
然后自己画了画........0 0?.........0 0!2^1维和2^2维画了几种2333尼玛就是个找规律啊,摔!
规律:答案分成四部分,左上部分 = 右上部分= 左下部分,右下部分跟他们相反(应该也有其他规律,不过懒得看了= =)(我才不说我是靠2^1维2^2维强行猜的规律= =)
求2^(k-1)维扩展到2^k维,所以从2^1维扩展到2^9维,进行预处理
#include <iostream> #include <algorithm> #include <cstdio> #include <stdlib.h> #include <cmath> #include <cstring> #include <string.h> #include <cstdlib> #include <iostream> #include <set> using namespace std; int a[550][550]; int main() { int n; memset(a, 0, sizeof(a)); a[0][0] = 1; int cnt = 1; int sum = 9; while(sum--){ for(int i = 0; i < cnt; i++){ for(int j = 0; j < cnt; j++){ a[i + cnt][j] = a[i][j + cnt] = a[i][j]; a[i + cnt][j + cnt] = -a[i][j]; } } cnt *= 2; } while(scanf("%d", &n) != EOF){ int ans = 1; for(int i = 0; i < n; i++) ans *= 2; for(int i = 0; i < ans; i++){ for(int j = 0; j < ans; j++){ if(a[i][j] == 1) printf("+"); else printf("*"); } printf("\n"); } } return 0; }
相关文章推荐
- make clean与make distclean的区别
- CSS文本对齐text-align详解
- DevOps on Android: 加速 App 从代码到上线
- C#类的 static变量
- 商城分类导航效果
- Spark-Cassandra-Connector 插入数据函数saveToCassandra
- Android 内存优化
- win 命令行常用命令
- android sqlite orm
- 解决ssh连接慢(有时候等半分钟才出现密码输入提示)的方法
- DevOps on Android: 加速 App 从代码到上线
- 信息滚动效果制作
- TweenAnimation 补间动画
- AS关于buildToolVersion与CompileSdkVersion的区别
- 小娜学法(10):王俊秀是什么人?
- 合并静态库总结
- Hdu 1233 还是畅通工程
- 实用的Android Studio 插件
- Oracle使用SQL传输表空间
- Android 代码混淆 选项说明