Codeforces Round #337 (Div. 2) 610C Harmony Analysis(脑洞)
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个相互垂直的向量.
观察给出的数据, 无限脑洞...
AC代码:
#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
#include "queue"
#include "stack"
#include "cmath"
#include "utility"
#include "map"
#include "set"
#include "vector"
#include "list"
#include "string"
#include "cstdlib"
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
int n;
int main(int argc, char const *argv[])
{
scanf("%d", &n);
n = 1 << n;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j)
printf("%c", __builtin_parity(i & j) ? '*' : '+');
printf("\n");
}
return 0;
}
列举四个位运算函数:
- int __builtin_ffs (unsigned int x)
返回x的最后一位1的是从后向前第几位,比方7368(1110011001000)返回4。 - int __builtin_clz (unsigned int x)
返回前导的0的个数。 - int __builtin_ctz (unsigned int x)
返回后面的0个个数,和__builtin_clz相对。 - int __builtin_popcount (unsigned int x)
返回二进制表示中1的个数。 - int __builtin_parity (unsigned int x)
返回x的奇偶校验位,也就是x的1的个数模2的结果。 - 摘自:点击打开链接
Codeforces Round #337 (Div. 2) 610C Harmony Analysis(脑洞)的更多相关文章
- Codeforces Round #337 (Div. 2) C. Harmony Analysis 构造
C. Harmony Analysis 题目连接: http://www.codeforces.com/contest/610/problem/C Description The semester i ...
- Codeforces Round #337 (Div. 2) C. Harmony Analysis 数学
C. Harmony Analysis The semester is already ending, so Danil made an effort and decided to visit a ...
- Codeforces Round #337 (Div. 2) C. Harmony Analysis
题目链接:http://codeforces.com/contest/610/problem/C 解题思路: 将后一个矩阵拆分为四个前一状态矩阵,其中三个与前一状态相同,剩下一个直接取反就行.还有很多 ...
- Codeforces Round #337 (Div. 2)
水 A - Pasha and Stick #include <bits/stdc++.h> using namespace std; typedef long long ll; cons ...
- Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树扫描线
D. Vika and Segments 题目连接: http://www.codeforces.com/contest/610/problem/D Description Vika has an i ...
- Codeforces Round #337 (Div. 2) B. Vika and Squares 贪心
B. Vika and Squares 题目连接: http://www.codeforces.com/contest/610/problem/B Description Vika has n jar ...
- Codeforces Round #337 (Div. 2) A. Pasha and Stick 数学
A. Pasha and Stick 题目连接: http://www.codeforces.com/contest/610/problem/A Description Pasha has a woo ...
- Codeforces Round #337 (Div. 2) D. Vika and Segments (线段树+扫描线+离散化)
题目链接:http://codeforces.com/contest/610/problem/D 就是给你宽度为1的n个线段,然你求总共有多少单位的长度. 相当于用线段树求面积并,只不过宽为1,注意y ...
- Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树 矩阵面积并
D. Vika and Segments Vika has an infinite sheet of squared paper. Initially all squares are whit ...
随机推荐
- 由Request Method:OPTIONS初窥CORS(转)
刚接触前端的时候,以为HTTP的Request Method只有GET与POST两种,后来才了解到,原来还有HEAD.PUT.DELETE.OPTIONS…… 目前的工作中,HEAD.PUT.DELE ...
- POJ-2420 A Star not a Tree? 梯度下降 | 模拟退火
题目链接:https://cn.vjudge.net/problem/POJ-2420 题意 给出n个点,找一个点,使得这个点到其余所有点距离之和最小. 思路 一开始就在抖机灵考虑梯度下降,猜测是个凸 ...
- Centos6.6 系统优化
1:最小化安装 2:修改网卡 vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0HWADDR=52:54:00:0e:c2:c3TYPE ...
- Centos7&docker-ce&compose&wordpress
如题,最近帮人装个WordPress,想起来用docker方便,这里做个记录. 原文:https://my.oschina.net/finchxu/blog/2877580 因为docker要求lin ...
- linux 系统相关命令
说明:此篇以 Debian ( ubuntu16.04 ) 命令为例 1. tab键默认是不能自动补全命令 apt install bash-completion // 安装完成之后重启系统 2. 虚 ...
- 紫书 例题8-17 UVa 1609 (构造法)(详细注释)
这道题用构造法, 就是自己依据题目想出一种可以得到解的方法, 没有什么规律可言, 只能根据题目本身来思考. 这道题的构造法比较复杂, 不知道刘汝佳是怎么想出来的, 我想的话肯定想不到. 具体思路紫书上 ...
- Hdu4786
Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- CCEditBox/CCEditBoxImplAndroid
#ifndef __CCEDITBOXIMPLANDROID_H__ #define __CCEDITBOXIMPLANDROID_H__ #include "cocos2d.h" ...
- Linux 文件系统初步
在Linux系统中,假设我们想要知道一个文件的详细信息,那么最简便的方法自然就是ls命令了.例如以下图所看到的:当在shell输入命令"ls -l old"时,在下方就会 ...
- poj_3371
一道模拟题,写的有点麻烦 #include<iostream> #include<cstring> #include<cstdio> #include<alg ...