华为OJ矩阵乘法计算量估算
来源:互联网 发布:单片机datesheet是什么 编辑:程序博客网 时间:2024/05/01 14:47
输入多行,先输入要计算乘法的矩阵个数n,每个矩阵的行数,列数,总共2n的数,最后输入要计算的法则
3 //矩阵个数n
50 10 //矩阵A的行数50,列数10
10 20 //矩阵B的行数10,列数20
20 5 //矩阵C的行数20,列数5
(A(BC)) //矩阵从A开始命名,A、B、C、D...以此类推,通过括号表示运算顺序
输出需要进行的乘法次数
#include <iostream> #include <vector>#include <string>#include <stack>#include <map>#include <algorithm>using namespace std;struct matrix{int row;int col;};void main(){vector<matrix> vec;stack<matrix> sta;int n;cin >> n;for (int i = 0; i < n; i++){matrix tmp;cin >> tmp.row >> tmp.col;vec.push_back(tmp);}string str;cin >> str;int result = 0;for (int i = 0; i < str.length(); i++){if (str[i] >= 'A'&&str[i] <= 'Z'){int index = str[i] - 'A';sta.push(vec[index]);}else if (str[i] == ')'){matrix value1 = sta.top();sta.pop();matrix value2 = sta.top();sta.pop();matrix value3;value3.row = value2.row;value3.col = value1.col;sta.push(value3);result += value2.row*value2.col*value1.col;}}cout << result;}
0 0
- 华为OJ矩阵乘法计算量估算
- 【华为OJ】【098-矩阵乘法计算量估算】
- 华为OJ——矩阵乘法计算量估算
- 华为OJ——矩阵乘法计算量估算
- 矩阵乘法计算量估算
- 华为OJ(矩阵乘法计算量估计)
- 华为机试:无线OSS-高精度整数加法、矩阵乘法计算量估算
- 【华为oj】矩阵乘法
- 华为oj 矩阵乘法
- 华为oj 矩阵乘法
- 【华为OJ】矩阵乘法
- 华为OJ:矩阵乘法
- 华为OJ(矩阵乘法)
- 【华为OJ】【042-矩阵乘法】
- 华为OJ 初级:矩阵乘法
- 华为oj初级 矩阵乘法
- Java算法---华为oj矩阵乘法
- 华为OJ题目(十七):矩阵乘法
- 小学数学
- JAVA——String类
- ssl讲解
- 爬新浪国内新闻网的某个新闻的评论
- poj 1189 钉子和小球
- 华为OJ矩阵乘法计算量估算
- Adventure of Super Mario UVA
- code[vs] 1014 装箱问题(01背包)
- C++笔记(二)
- POJ-3686-The Windy's(KM/费用流)
- 初学快速幂详细讲解
- 事件的三个阶段:捕获阶段 目标阶段 冒泡阶段
- C#之类私有成员的安全访问
- redux 配合 react 在项目中的使用(个人总结与备忘)