UVA
来源:互联网 发布:美甲软件 编辑:程序博客网 时间:2024/05/16 15:55
题目 : 计算一个矩阵乘法的次数
讲道理,应该用struct的,但是最近几天写stl写傻了。。。直接上了pair,也不知道是为什么。。。
#include <algorithm>#include <cstring>#include <iostream>#include <cstdio>#include <queue>#include <stack>#include <map>using namespace std;#define Pair pair<int,int>int n;map<int ,pair<int,int> > mat;int getdata(){ char s[1005]; stack<pair<Pair,int> > S; while(cin.getline(s,1005)) { int slen = strlen(s); int flag = 1; for(int i = 0; i < slen; i++) { if(s[i] == ')') { pair<Pair,int> b = S.top(); S.pop(); pair<Pair,int> a = S.top(); S.pop(); if(a.first.second != b.first.first) { flag = 0; printf("error\n"); break; } else { int jieguo = (a.first.first)*(a.first.second)*(b.first.second); S.push(pair<Pair,int>(Pair(a.first.first,b.first.second),jieguo+a.second+b.second)); } } if(isupper(s[i])) { int a = s[i] - 'a'; S.push(pair<Pair,int>(Pair(mat[a].first,mat[a].second),0)); } } if(flag) printf("%d\n",S.top().second); }}int main(){ scanf("%d",&n); for(int i = 0; i < n ; i++) { char s[2]; int a,b; scanf("%s%d%d",s,&a,&b); mat[s[0] -'a'] = Pair(a,b); } getchar(); getdata(); return 0;}
0 0
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- FTP登录提示Can't open data connection for transfer of "/"
- 类的静态变量与成员变量的区别
- this的理解
- 洛谷 P3225 [HNOI2012]矿场搭建
- Java 核心基础技术(二)
- UVA
- 一起做RGB-D SLAM (2)
- Flume使用namespace操作
- 混合高斯模型的EM求解(Mixtures of Gaussians)及Python实现源码
- uploadfive详解
- 【cocos2dx】TMXTiledMap增加碰撞体
- 骄傲的代价
- sql优化思路整理
- View 绘制流程