cf 337 div2 c
3 seconds
256 megabytes
standard input
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?
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)分成左上,右上,左下,右下四个方阵,假设当前我们已知k - 1时的方阵,只要把左上,左下右上填成与k - 1相同方阵,右下填成
与k - 1方阵反相即可。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> using namespace std; const int maxn = ;
char mar[maxn][maxn];
int k; char invert(char x) {
return x == '+' ? '*' : '+';
} int main() {
scanf("%d", &k);
mar[][] = '+';
for (int i = ; i <= k; ++i) {
int a = pow(, i - );
int b = pow(, i);
for (int r = ; r < a; ++r) {
for (int c = a; c < b; ++c) {
mar[r][c] = mar[r][c - a];
}
} for (int r = a; r < b; ++r) {
for (int c = ; c < a; ++c) {
mar[r][c] = mar[r - a][c];
}
} for (int r = a; r < b; ++r) {
for (int c = a; c < b; ++c) {
mar[r][c] = invert(mar[r][c - a]);
}
}
} int a = pow(, k);
for (int i = ; i < a; ++i) {
for (int j = ; j < a; ++j) {
printf("%c", mar[i][j]);
}
printf("\n");
} return ;
}
cf 337 div2 c的更多相关文章
- cf 442 div2 F. Ann and Books(莫队算法)
cf 442 div2 F. Ann and Books(莫队算法) 题意: \(给出n和k,和a_i,sum_i表示前i个数的和,有q个查询[l,r]\) 每次查询区间\([l,r]内有多少对(i, ...
- CF#603 Div2
差不多半年没打cf,还是一样的菜:不过也没什么,当时是激情,现在已是兴趣了,开心就好. A Sweet Problem 思维,公式推一下过了 B PIN Codes 队友字符串取余过了,结果今天早上一 ...
- CF R631 div2 1330 E Drazil Likes Heap
LINK:Drazil Likes Heap 那天打CF的时候 开场A读不懂题 B码了30min才过(当时我怀疑B我写的过于繁琐了. C比B简单多了 随便yy了一个构造发现是对的.D也超级简单 dp了 ...
- CF#581 (div2)题解
CF#581 题解 A BowWow and the Timetable 如果不是4幂次方直接看位数除以二向上取整,否则再减一 #include<iostream> #include< ...
- [CF#286 Div2 D]Mr. Kitayuta's Technology(结论题)
题目:http://codeforces.com/contest/505/problem/D 题目大意:就是给你一个n个点的图,然后你要在图中加入尽量少的有向边,满足所有要求(x,y),即从x可以走到 ...
- CF 197 DIV2 Xenia and Bit Operations 线段树
线段树!!1A 代码如下: #include<iostream> #include<cstdio> #define lson i<<1 #define rson i ...
- CF#345 div2 A\B\C题
A题: 贪心水题,注意1,1这组数据,坑了不少人 #include <iostream> #include <cstring> using namespace std; int ...
- CF R303 div2 C. Woodcutters
C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- CF 192 Div2
A.Cakeminator 暴搞之,从没有草莓覆盖的行.列遍历 char map[30][30]; int vis[30][30]; int hang[30],lie[30]; int main() ...
随机推荐
- Fragment中的setUserVisibleHint()方法调用
使用Fragment的时候难免会遇到想在视图可见与不可见之中做些操作.此时一般会想到类似Activity中的onResume()和onPause()方法.Fragment中也确实有这两个方法,然而亲測 ...
- [转]Dialog
在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,在我们使用Android的过程中,我归纳了一 ...
- element-ui table 页面加载时,动态渲染后台传过来的数据(springmvc)
jsp页面 <%@ page contentType="text/html;charset=UTF-8" language="java" %> &l ...
- 使用 Jenkins + GitHub + Nginx + HTTPS 搭建静态网站
参考https://www.imooc.com/article/20079 http://www.haoduoyu.cc/
- E20170626-hm
authenticate vt. 认证,证明是真实的.可靠的或有效的; 鉴定,使生效; author n. 作者; 著作家; 创造者; 发起人;
- codevs1004四子连棋
1004 四子连棋 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 在一个4*4的棋盘上摆放了14颗棋子,其中有7颗白 ...
- JVM-垃圾回收器
目录 垃圾收集器 Serial收集器 Serial Old 收集器 ParNew 收集器 Parallel Scavenge 收集器 (并行清除) /'pærəlɛl/ /'skævɪndʒ/ Par ...
- 【Leetcode】84. Largest Rectangle in Histogram 85. Maximal Rectangle
问题描述: 84:直方图最大面积. 85:0,1矩阵最大全1子矩阵面积. 问题分析: 对于84,如果高度递增的话,那么OK没有问题,不断添加到栈里,最后一起算面积(当然,面积等于高度h * disPo ...
- ios的认识
刚进了ios兴趣班,第一次使用苹果电脑,因为苹果电脑和windows电脑使用的区别很大.所以老师教我们苹果电脑的基本使用,以及关于苹果产品的一些认识.我听得热血沸腾,对苹果开发越来越感兴趣,相信下次上 ...
- js基础---元素操作时字符串拼接
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...