模板-->Matrix重载运算符:+,-,x
2024-09-16 14:03:59
如果有相应的OJ题目,欢迎同学们提供相应的链接
相关链接
简单的测试
INPUT:
1 2 3 1
3 4 3 -1
OUTPUT:
+ 4 3
6 3
- -2 1
0 5
x 8 -1
18 -1
代码模板
const int MAXN=1; #modify here
const int MAXM=1; #modify here
struct Matrix{
int n,m;
int a[MAXN][MAXM];
void clear(){
n=m=0;
memset(a,0,sizeof(a));
}
Matrix operator +(const Matrix &b) const{
Matrix tmp;
tmp.n=n;tmp.m=m;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
tmp.a[i][j]=a[i][j]+b.a[i][j];
return tmp;
}
Matrix operator -(const Matrix &b) const{
Matrix tmp;
tmp.n=n;tmp.m=m;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
tmp.a[i][j]=a[i][j]-b.a[i][j];
return tmp;
}
Matrix operator *(const Matrix &b) const{
Matrix tmp;
tmp.clear();
tmp.n=n;tmp.m=b.m;
for(int i=0;i<n;i++)
for(int j=0;j<b.m;j++)
for(int k=0;k<m;k++)
tmp.a[i][j]+=a[i][k]*b.a[k][j];
return tmp;
}
};
最新文章
- webform Repeater重复器、地址栏传值、Response
- 多人开发Xcode工程冲突,打不开解决办法
- Google Maps地图投影全解析(3):WKT形式表示
- C/C++程序员必须熟练应用的开源项目[转]
- iOS-----类和对象,nil/Nil/NULL的区别
- java 14 -10 Calendar类以及练习
- ActiveMQ点对点的消息发送案例
- MAX-HEAPIFY(2/3n的疑惑)
- Centos7下建立rubymine快捷方式到侧栏或桌面
- JavaMail邮件发送不成功的那些坑人情况及分析说明
- Bootstrap3 表格-紧缩表格
- Oracle EBS json
- Java面试总结之AIO与NIO
- 简述servlet
- 【SpringBoot系列1】SpringBoot整合MyBatis
- 获得discuz7.2 目录下所有文件,并写到txt
- 3. Recursive AutoEncoder(递归自动编码器)
- Linux下CPU信息的查看
- CodeForces - 983B XOR-pyramid(区间dp,异或)
- JAVA练手--集合
热门文章
- 实用的透明背景mark图标
- sphinx (coreseek)——2、区段查询实例
- 老oj曼哈顿最小生成树
- Redux1
- IOS设计模式之三:MVC模式
- Hadoop环境搭建-入门伪分布式配置(Mac OS,0.21.0,Eclipse 3.6)
- OLAP 大表和小表并行hash join
- 如果你不好好玩printf
- 解决SecureCRT中文版“数据库里没找到防火墙‘无’”的错误提示
- AlgorithmsI PA2: Randomized Queues and Deques Subset