hdu1082
#include<iostream>
#include<stack>
#include<string>
#include<cctype>
using namespace std;
#define N 30
struct node
{
char m;
int r,c;
} a[N];
string s;
bool process(int& ans)
{
int len,i;
stack<node> sta;
node x,y,t;
len=s.length();
if(len==1)
{
ans=0;
return true;
}
ans=0;
for(i=0;i<len;i++)
if(isupper(s[i]))
sta.push(a[s[i]-'A']);
else if(s[i]==')')
{
x=sta.top();
sta.pop();
y=sta.top();
sta.pop();
if(x.r!=y.c) return false;
t.r=y.r;
t.c=x.c;
ans+=y.r*y.c*x.c;
sta.push(t);
}
return true;
}
int main()
{
int n,i,ans;
char c;
cin>>n;
for(i=0;i<n;i++)
{
getchar();
cin>>c;
a[c-'A'].m=c;
cin>>a[c-'A'].r>>a[c-'A'].c;
}
while(cin>>s)
{
if(!process(ans))
cout<<"error"<<endl;
else
cout<<ans<<endl;
}
return 0;
}
hdu1082的更多相关文章
- Matrix Chain Multiplication[HDU1082]
Matrix Chain Multiplication Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- hdu-1082 Matrix Chain Multiplication---栈的运用
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1082 题目大意: 题意大致是N个矩阵,如果要求计算的矩阵例如(AB),如果A的列等于B的行,进行:A ...
随机推荐
- 登陆获取shell时的配置文件加载过程
最近遇到一台ubuntu服务器登陆时默认语言环境变量变成posix问题, 导致中文显示乱码,影响程序的正常运行 # locale LANG= LANGUAGE= LC_CTYPE="POSI ...
- EntityFramework 学习 一 Persistence in Entity Framework
实体框架的持久化 当用EntityFramework持久化一个对象时,有两种情形:连接的和断开的 1.连接场景:使用同一个context上下文从数据库中查询和持久化实体时,查询和持久化实体期间,con ...
- 十二 Django框架,自定义分页
自定义分页模块 #!/usr/bin/env python #coding:utf-8 from django.utils.safestring import mark_safe #封装分页类模块 c ...
- ES提高数据压缩的设置——单字段,去掉source和all
curl -XPUT 'http://localhost:9200/hec_test3' -d ' { "mappings": { "hec_type3": { ...
- python基础-条件语句if
if语句: if 判断条件: 执行语句 else: 执行语句 flag = Falsename = 'huipaodexiong'if name == 'python': flag = True ...
- Mex混合编程专题一:Mex环境搭建
使用Matlab时间长了,难免会碰到使用mex文件的经历,不管是别人的还是自己的,就比如MatConvNet(http://www.vlfeat.org/matconvnet/)使用了混合编程的技术实 ...
- bzoj1002轮状病毒
高精度练习题 根据什么什么基尔霍夫矩阵 反正就是高精度练习 #include<iostream> #include<cstdio> using namespace std; s ...
- 【Google】非下降数组
转自九章算法公众号 题目描述 给出包含n个整数的数组,你的任务是检查它是否可以通过修改至多一个元素变成非下降的.一个非下降的数组array对于所有的i(1<=i<n)满足array[i-1 ...
- 汇编题目:按A键,当松开的时显示字母A
安装一个新的int9中断例程,功能:在DOS下,按下“A”键后,除非不再松开,如果松开,就显示满屏的“A”:其他的按键照常处理.提示:按下一个键时产生的扫描码称为通码,松开一个键时产生的扫描码称为断码 ...
- Poj 1973 Software Company(二分+并行DP)
题意:软件公司接了两个项目,来自同一个合同,要一起交付.该公司有n个程序猿来做这两个项目A和B,每个项目都被分为m个子项目,给定每个程序猿做一个A中的子项目需要的时间Xi秒,和做B中的子项目所需时间Y ...