POJ 2961 Sylvester construction 哈达玛矩阵
来源:互联网 发布:淘宝极有家和中国质造 编辑:程序博客网 时间:2024/04/25 04:13
点击打开链接
Sylvester construction
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 1201 Accepted: 556
Description
A Hadamard matrix of order n is an n x n matrix containing only 1s and -1s, called Hn, such that HnHnT = nIn where In is the n x n identity matrix. An interesting property of Hadamard matrices is that they have the maximum possible determinant of any n x n matrix with elements in the range [-1, 1]. Hadamard matrices have applications in errorcorrecting codes and weighing design problems.
The Sylvester construction is a way to create a Hadamard matrix of size 2n given Hn. H2n can be constructed as:
for example:
and so on.
In this problem you are required to print a part of a Hadamard matrix constructed in the way described above.
The Sylvester construction is a way to create a Hadamard matrix of size 2n given Hn. H2n can be constructed as:
for example:
and so on.
In this problem you are required to print a part of a Hadamard matrix constructed in the way described above.
Input
The first number in the input is the number of test cases to follow. For each test case there are five integers: n, x, y, w and h. n will be between 1 and 262 (inclusive) and will be a power of 2. x and y specify the upper left corner of the sub matrix to be printed, w and h specify the width and height respectively. Coordinates are zero based, so 0 ≤ x,y < n. You can assume that the sub matrix will fit entirely inside the whole matrix and that 0 < w,h ≤ 20. There will be no more than 1000 test cases.
Output
For each test case print the sub matrix followed by an empty line.
Sample Input
32 0 0 2 24 1 1 3 3268435456 12345 67890 11 12
Sample Output
1 11 -1-1 1 -11 -1 -1-1 -1 11 -1 -1 1 1 -1 -1 1 1 -1 -1-1 -1 1 1 -1 -1 1 1 -1 -1 11 1 1 -1 -1 -1 -1 1 1 1 1-1 1 -1 -1 1 -1 1 1 -1 1 -11 -1 -1 -1 -1 1 1 1 1 -1 -1-1 -1 1 -1 1 1 -1 1 -1 -1 1-1 -1 -1 -1 -1 -1 -1 1 1 1 11 -1 1 -1 1 -1 1 1 -1 1 -1-1 1 1 -1 -1 1 1 1 1 -1 -11 1 -1 -1 1 1 -1 1 -1 -1 1-1 -1 -1 1 1 1 1 1 1 1 11 -1 1 1 -1 1 -1 1 -1 1 -1
Source
Svenskt Mästerskap i Programmering/Norgesmesterskapet 2004
哈达玛(Hadamard)矩阵是由+1和-1元素构成的且满足Hn*Hn’=nI(这里Hn’为Hn的转置,I为单位方阵)n阶方阵。
本题要求打印构造出来的Hadamard矩阵的一部分。
//356K16MS#include<stdio.h>int H[2][2]={{1,1},{1,-1}};long long dfs(long long x,long long y){ if(x<2&&y<2)return H[x][y]; int i=0,j=0; if(x>=2) { i=1; while(i*2<=x) i*=2; x-=i; } if(y>=2) { j=1; while(j*2<=y) j*=2; y-=j; } if(i==j)return -dfs(x,y);//位于4区 else if(i>j)return dfs(x,y+j);//位于3区 else return dfs(x+i,y);//位于2区}int main(){ int t; scanf("%d",&t); while(t--) { long long n,x,y,w,h,i,j; scanf("%I64d%I64d%I64d%I64d%I64d",&n,&x,&y,&w,&h); for(i=y;i<y+h;i++) { for(j=x;j<x+w-1;j++) printf("%d ",dfs(i,j)); printf("%d\n",dfs(i,j)); } printf("\n"); } return 0;}
0 0
- POJ 2961 Sylvester construction 哈达玛矩阵
- 哈达玛(Hadamard)矩阵
- 【TOJ 2421.】 Sylvester construction【水题】
- 数组的常用算法(3) - 哈达玛矩阵
- 沃尔什-哈达玛变换
- 辨析matmul product(一般矩阵乘积),hadamard product(哈达玛积)、kronecker product(克罗内克积)
- poj 3352 Road Construction
- POJ 3352 Road Construction
- POJ 3352: Road Construction
- POJ 3352 Road Construction
- poj 3352 Road Construction
- poj 3352 Road Construction
- POJ 3352 Road Construction
- poj 3352 Road Construction
- POJ 3352 Road Construction
- POJ 3352 Road Construction
- poj 3352 Road Construction
- poj 3352 Road Construction
- 关于Activity和task的设计思路与方法
- 在IOS中使用KeychainItemWrapper保存用户名和密码实现记住密码功能
- Linux下用C编写WebSocet服务以响应HTML5的WebSocket请求
- 工作过程中的一些小细节与大问题
- Android 增加第三方库
- POJ 2961 Sylvester construction 哈达玛矩阵
- 使用匿名类的构造函数
- AttachCurrentThread
- HTML5本地数据库(SQLite)示例
- 如何处理javascript中var类型有效数据极限值问题(超大数据)
- keepalive学习之软件设计
- cocos2d-x中的lua调试
- 临时表空间使用情况查询
- OCP-1Z0-053-200题-44题-622