紫书例题6-3 UVa442 (栈
来源:互联网 发布:淘宝怎么好友代付 编辑:程序博客网 时间:2024/05/01 08:38
这个应该也是个水题的 可惜题意不是很好理解
紫书上也没说怎么构造新的矩形2333
题目给的样例很给力1A
#include <cstdio>#include <cstring>#include <cmath>#include <queue>#include <stack>#include <map>#include <set>#include <iostream>#include <vector>#include <algorithm>using namespace std;#define ll long long#define N 1000const int mod = 1e9+7;struct node { int x;int y;}p[100];stack<node> s;void init(){ while(!s.empty()) s.pop();}char str[N];int main(){ int n; scanf("%d",&n); char ch; int a,b; for(int i = 0;i < n; i++) { getchar(); scanf("%c%d%d",&ch,&a,&b); p[ch-'A'].x = a; p[ch-'A'].y = b; } while(~scanf("%s",str)) { bool flag = true; int sum = 0; init(); int len = strlen(str); for(int i = 0;i < len; i++) { if(str[i] == '(') continue; if(str[i]>='A' && str[i]<='Z') { s.push(p[str[i]-'A']); } if(str[i] == ')') { node m = s.top(); s.pop(); node n = s.top(); s.pop(); if(m.x != n.y) { flag = false; break; //不符合要求,直接GG } node zz; //构造个新的的矩阵,扔进栈中 zz.x = n.x, zz.y = m.y; s.push(zz); sum += n.x * m.y * n.y; } } if(flag) printf("%d\n",sum); else puts("error"); memset(str,0,sizeof*str); }return 0;}
0 0
- 紫书例题6-3 UVa442 (栈
- 例题6-3 矩阵链乘 UVA442
- Uva442 Matrix Chain Multiplication【stack】【例题6-3】
- UVa442 例题6-3 矩阵链乘(Matrix Chain Multiplication)
- uva442 栈
- UVA442栈
- UVA442
- uva442
- UVA442
- UVa442
- uva442
- uva442
- uva442
- UVa442
- UVa442
- UVa442
- UVa442
- 紫书例题6-2 UVa 514 ( 栈
- poj1113 Wall【凸包】
- c# dropdownlist json ajax
- javascript 简单滚动图片
- 可伸缩架构简短系列
- 杭电oj 1175连连看
- 紫书例题6-3 UVa442 (栈
- nginx 常见错误及优化
- 单例模式
- 表达式计算(中缀转后缀,然后求值)
- 《java学习笔记》MD5加密算法
- mysql-按天或者按月统计数据
- SSM框架整合(三)
- ORA-12519: TNS:no appropriate service handler found 解决
- ubuntu下安装lua的时候出现 lua.c:80:31: fatal error: readline/readline.h: 没有那个文件或目录 这样的报错