【53.57%】【codeforces 610C】Harmony Analysis
time limit per test3 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
Examples
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
【题解】
规律题;
k和k-1的答案存在如下关系;
上图中的方框表示k-1时的答案;
把它按照上述方式复制3份,第4份则在原来的基础上取反;(用1表示+,0表示减);
比如样例输入
++**
+*+*
++++
+**+
//->
1100
1010
1111
1001
//->相同的3份取反的一份
1100 1100
1010 1010
1111 1111
1001 1001
1100 0011
1010 0101
1111 0000
1001 0110
/*而这正是k=3时的答案;右下角那个
上面两个方框是肯定满足的;
为了让下面两个方框在乘的时候也满足;
相当于左边取A,右边取它的相反数-A;这样一减就是0;
如果一个答案符合要求则全部取反还是能符合要求的;
所以右下角取反不会影响下面两个的答案正确性;
然后又能让上面两个方框的乘下面两个方框的向量的时候积为0;所以是符合要求的;
*/
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
#define lson L,m,rt<<1
#define rson m+1,R,rt<<1|1
#define LL long long
using namespace std;
const int MAXN = 1000;
const int dx[5] = {0,1,-1,0,0};
const int dy[5] = {0,0,0,-1,1};
const double pi = acos(-1.0);
struct abc
{
int a[1000][1000];
};
int k;
abc ans[10];
void input_LL(LL &r)
{
r = 0;
char t = getchar();
while (!isdigit(t) && t!='-') t = getchar();
LL sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
}
void input_int(int &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)&&t!='-') t = getchar();
int sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
}
int main()
{
// freopen("F:\\rush.txt","r",stdin);
ans[0].a[1][1] = 0;
for (k= 1;k <= 9;k++)
{
for (int i = 1;i <= 1<<(k-1);i++)
for (int j = 1;j <= 1<<(k-1);j++)
{
ans[k].a[i][j] = ans[k-1].a[i][j];
ans[k].a[i+(1<<(k-1))][j] = ans[k-1].a[i][j];
ans[k].a[i][j+(1<<(k-1))] = ans[k].a[i][j];
ans[k].a[i+(1<<(k-1))][j+(1<<(k-1))] = !ans[k].a[i][j];
}
}
input_int(k);
for (int i = 1;i <= 1<<k;i++)
{
for (int j = 1;j <= 1<<k;j++)
if (ans[k].a[i][j])
putchar('+');
else
putchar('*');
puts("");
}
return 0;
}
【53.57%】【codeforces 610C】Harmony Analysis的更多相关文章
- Codeforces 610C:Harmony Analysis(构造)
[题目链接] http://codeforces.com/problemset/problem/610/C [题目大意] 构造出2^n个由1和-1组成的串使得其两两点积为0 [题解] 我们可以构造这样 ...
- 【53.57%】【codeforces 722D】Generating Sets
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- 【57.97%】【codeforces Round #380A】Interview with Oleg
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【34.57%】【codeforces 557D】Vitaly and Cycle
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【Educational Codeforces Round 53 (Rated for Div. 2) C】Vasya and Robot
[链接] 我是链接,点我呀:) [题意] [题解] 如果|x|+|y|>n 显然.从(0,0)根本就没法到(x,y) 但|x|+|y|<=n还不一定就能到达(x,y) 注意到,你每走一步路 ...
- 【codeforces 750C】New Year and Rating(做法2)
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 750A】New Year and Hurry
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 750C】New Year and Rating
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- 【风马一族_php】常用的语句
设置脚本的编码 <?php header('Content-type:text/html;charset=utf-8'); ?> 按原格式的输入内容 echo <pre>; ...
- Web富媒体应用
曾几何时,大家都在以flash开发的富媒体交互应用而感叹,一是叹它的丰富多彩的效果,一是叹它的局限.性能以及加载时长等问题. 如今,市场以及基本上没有flash什么事情了,而是H5的天下,可惜,移动应 ...
- Chef 安装
http://www.tuicool.com/articles/RnAVn2 三个角色: chef server, chef workstation, chef nodes(chef clients) ...
- Java练习 SDUT-3848_Shift Dot
Shift Dot Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 给出平面直角坐标系中的一点,并顺序给出n个向量,求该 ...
- CSS Specificity
CSS的specificity特性或称非凡性,它是一个衡量CSS值优先级的一个标准. 其实就是解决冲突,当同一个元素被CSS选择符选中,按照优先权取舍不同的CSS规则. specificity用一个四 ...
- 【NS2】NS2 教學手冊(转载)
之前做毕设的时候搜索NS2的相关资料,发现这个里面涵盖很广,特此收藏,感谢原作者的辛勤劳作. NS2 教學手冊 ( NS2 Learning Guide) [快速連結區] My works 中文影音 ...
- 利用IDEA构建springboot应用-如何优雅的使用mybatis
orm框架的本质是简化编程中操作数据库的编码 一个是宣称可以不用写一句SQL的hibernate, 一个是可以灵活调试动态sql的mybatis mybatis-spring-boot-starter ...
- HTTP Status 500 - java.lang.ClassNotFoundException: org.apache.jsp.register_jsp
你搜一下你的页面中是不是有<!---->的注释 去掉就好了 改成jsp的注释 1).JSP页面中的HTML注释 JSP页面中的HTML注释使用“<!—”和“-->”创建,它的具 ...
- python 列表对象的增减
- Part17—触摸屏显身手—Part17.1—原理简介