【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 ...
随机推荐
- 《spring boot》8.2章学习时无法正常启动,报“ORA-00942: 表或视图不存在 ”
在学习<spring boot>一书的过程中,由于原书作者难免有一些遗漏的的地方,或者系统.软件版本不一致.框架更新等各种因素,完全安装书中源码页不能实现项目的正常启动 在8.2章节,演示 ...
- C++五:重载 多态
C++五:重载与多态 一:概述 多态是指同样的消息被不同类型的对象接收导致不同的行为,即接口的多种不同的实现方式.多态可分为静态多态与动态多态.多态类型可分为四类:重载多态,强制多态,包含多态,参 ...
- 一个 PHP 面试题
一个 PHP 面试题 $i = 0; $j =1; if ($i = 5 || ($j =6)) {echo $i,$j++;} 拿来当面试题不错. 实际并不会这样用,但这个题可以考基础.
- 无人驾驶——对frenet坐标的理解
好的确定车和路之间的关系,我们通常将车辆的在大地坐标坐标转化为车辆和道路之间的frenet坐标. 可能有人会疑问为什么转换后就方便了呢?我们来看一个例子. 在大地坐标下: 无人车首先要知道红色车的位置 ...
- 使用css制作三角
1. 字符实现三角效果关于字符实现三角我早在09年的时候就介绍了:使用字符实现兼容性的圆角尖角效果.一转眼两年过去了,这个技术开始被越来越多的人所熟知.使用的字符是正棱形“◆”字符,编码表示为◆ . ...
- AIDL基本用法
1. AIDL有什么用?用TA到目的是什么? 2. 怎么用AIDL? 1. AIDL有什么用? 1.1. 为了提高代码执行速度,将部分逻辑封入C/C++代码中 1.2. 为了调用这部分代码,使用JN ...
- 从零学React Native之05混合开发
本篇文章,我们主要讨论如何实现Android平台的混合开发. RN给Android端发送消息 首先打开Android Studio, Open工程, 在React Native项目目录下选择andro ...
- mysql 表名和字段、备注
select t1.table_schema ,t1.table_name ,t2.ordinal_position ,t2.column_name ,t2.data_type ,t2.charact ...
- 20-2 orm分组和聚合以及在项目中执行的一些方法
一 orm分组和聚合 参考:https://www.cnblogs.com/liwenzhou/p/8660826.html 1 表结构: # 第一张表 class Employee1(models ...
- 请注意更新TensorFlow 2.0的旧代码
TensorFlow 2.0 将包含许多 API 变更,例如,对参数进行重新排序.重新命名符号和更改参数的默认值.手动执行所有这些变更不仅枯燥乏味,而且容易出错.为简化变更过程并让您尽可能顺畅地过渡到 ...