题解 | #矩阵乘法计算量估算#

矩阵乘法计算量估算

https://www.nowcoder.com/practice/15e41630514445719a942e004edc0a5b

#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int count(vector<pair<int,int>> &vec, int a, int b){
    int sum;
    sum = vec[a].first * vec[a].second * vec[b].second;
    vec[a] = make_pair(vec[a].first,vec[b].second);
    //vec.erase(vec.begin() + b);
    return sum;
}

int main() {
    int n;
    cin>>n;
    vector<pair<int,int>> vec;
    while (n--){
        int a,b;
        cin>>a>>b;
        vec.push_back(make_pair(a,b));
    }
    stack<char> st;
    string str;
    cin >> str;
    int result = 0;
    for (auto ch : str){
        if (ch == '(')
            continue;
        if (ch == ')'){
            if (st.size() > 1){
                int num_2 = st.top() - 'A';
                st.pop();
                //int num_1 = st.top() - 'A';
                //st.pop();
                result += count(vec, st.top() - 'A', num_2);
                //cout<<"1:"<<result<<endl;
            }
        }
        else    st.push(ch);  
    }
    cout << result;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

会考什么呀?硬件岗
投递大疆等公司10个岗位
点赞 评论 收藏
分享
ccc6660204:直接转前端,明天开始学,把自己学过Java 什么的全都忘记,不要有任何惋惜,信我,坚持到大三下你会感谢我
计算机有哪些岗位值得去?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务