矩阵连乘 LRJ白书 p141 栈 解析表达式
#include<iostream>
#include<cstdio>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<fstream>
#include<memory>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 102
#define INF 1000000009
/*
利用栈解析表达式
*/
struct Matrix
{
int a, b;
Matrix(int _a = ,int _b=):a(_a),b(_b){}
}m[];
stack<Matrix> s;
int main()
{
int n;
scanf("%d", &n);
string str;
for (int i = ; i < n; i++)
{
cin >> str;
int k = str[] - 'A';
cin >> m[k].a >> m[k].b;
}
string expr;
while (cin >> expr)
{
int len = expr.length();
bool error = false;
int ans = ;
for (int i = ; i < len; i++)
{
if (isalpha(expr[i]))
s.push(m[expr[i] - 'A']);
else if (expr[i] == ')')
{
Matrix m2 = s.top(); s.pop();
Matrix m1 = s.top(); s.pop();
if (m1.b != m2.a)
{
error = true;
break;
}
ans += m1.a*m1.b*m2.b;
s.push(Matrix(m1.a, m2.b));
}
}
if (error)
cout << "error\n";
else
cout << ans << endl;
}
}
矩阵连乘 LRJ白书 p141 栈 解析表达式的更多相关文章
- 倒水问题(Fill,UVA 10603) lrj白书 p202
看着lrj的代码自己敲了一遍,还没调试成功.... 有时间再进行完善 /* 状态start到各个状态u1,u2,u3..... 的倒水量分别为u1.dist,u2.dist,u3.dist.... * ...
- Uva 548 二叉树的递归遍历lrj 白书p155
直接上代码... (另外也可以在递归的时候统计最优解,不过程序稍微复杂一点) #include <iostream> #include <string> #include &l ...
- Uva 122 树的层次遍历 Trees on the level lrj白书 p149
是否可以把树上结点的编号,然后把二叉树存储在数组中呢?很遗憾如果结点在一条链上,那将是2^256个结点 所以需要采用动态结构 首先要读取结点,建立二叉树addnode()+read_input()承担 ...
- 白书P61 - 点集配对问题
白书P61 - 点集配对问题 状压DP #include <iostream> #include <cstdio> #include <cstring> using ...
- 白书P60 - 硬币问题
白书P60 - 硬币问题 完全背包.DP #include <iostream> #include <cstdio> #include <cstring> usin ...
- poj2991 Crane(线段树+集合)白书例题
题目大意:起重机有n节,题目给出要调节的k节,每节调节成x度,求最后底部的起重机的坐标(最顶上的起点为(0,0)). 分析:一开始我看白书,看不懂他那个向量旋转的坐标是怎么来的,翻了很多博客,才发现, ...
- Uva10474-STL水题-白书
白书的一道水题.话说好久没认真做难题了.今天出了排名,所有队伍里倒数第一啊! 代码没什么可说的了. #include <algorithm> #include <cstring> ...
- UVA大模拟代码(白书训练计划1)UVA 401,10010,10361,537,409,10878,10815,644,10115,424,10106,465,10494
白书一:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=64609#overview 注意UVA没有PE之类的,如果PE了显示WA. UVA ...
- 《白书》上线段树RMQ的实现
白书上的线段树RMQ实现,自己重写了一遍: #include <bits/stdc++.h> using namespace std; const int MAXN=1<<17 ...
随机推荐
- E20171011-hm
Rendering engine 渲染引擎; 引擎; 绘图引擎; interactive adj. 互动的; 互相作用的,相互影响的; [计] 交互式的; defer vt. 使推迟; 使延 ...
- String Successor(模拟)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3490 题意:给出一个字符串,一个操作次数,每次操作从当前字符串最右边的字符 ...
- frameset的target属性
使用frameset时的target属性 (2012-09-18 08:19:31) 转载▼ 分类: java技术之路 一般常用的有四个属性 _blank 浏览器总在一个新打开.未命名的窗口中载入 ...
- 判断人员js
var allchooseEmpID = "";var allchooseEmpName = "";//自选经办人 function getJbrWinForM ...
- printf的字符型
参 数 说 明 %s 按实际宽度输出一个字符串 %ms m指定宽度(不足时左补空格,大于时按实际宽度输出) %-ms 左对齐,不足时右补空格 %m.ns 输出占m个字符位置,其中字符数最多n个,左 ...
- 【洛谷1654/BZOJ4318】OSU!(期望DP)
题目: 洛谷1654 分析: 本人数学菜得要命,这题看了一整天才看明白-- 先说说什么是"期望".不太严谨地说,若离散型随机变量(可以看作"事件")\(X\)取 ...
- PHP富文本编辑器 之Kindeditor的使用 一
一.下载编辑器源码 KindEditor 4.1.10 (2013-11-23) [1143KB] 下载页面: http://kindeditor.net/down.php 二.部署编辑器 将下载文件 ...
- 去除IOS苹果手机自带按钮样式的问题~
input[type="button"], input[type="submit"], input[type="reset"] { -web ...
- JS——缓慢动画封装
在知道如何获取内嵌式和外链式的标签属性值之后,我们再次封装缓慢动画: 单个属性 <!DOCTYPE html> <html> <head lang="en&qu ...
- windows phone 8 使用页面传对象的方式 实现页面间的多值传递
在做windows phone 开发的时候,会经常碰到页面间之间的跳转和传递数据,如果传递的值不多,只有两三个,我们通常使用NavigationService.Navigate(new Uri(&qu ...