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

矩阵乘法计算量估算

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

using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
    public static void Main()
    {
        var count = int.Parse(Console.ReadLine());
        var all = new List<XY>();
        for (var i = 0; i < count; i++)
        {
            var line = Console.ReadLine().Split(" ");
            var x = int.Parse(line[0]);
            var y = int.Parse(line[1]);
            all.Add(new XY {X = x, Y = y});
        }
        var all1 = new List<XY>();
        var last = Console.ReadLine().ToList();
        var pointer = 0;
        var result = 0;
        for(var i = 0; i< last.Count; i++)
        {
            if (last[i] == '(')
            {
                continue;
            }

            if(last[i] == ')')
            {
                var length = all1.Count;
                var x = all1[length - 2].X;
                var y = all1[length - 1].Y;
                result += all1[length - 1].X * all1[length - 1].Y * all1[length - 2].X;

                all1.RemoveAt(all1.Count - 1);
                all1.RemoveAt(all1.Count - 1);
                all1.Add(new XY {X = x, Y = y});
            }
            else
            {
                all1.Add(all[pointer]);
                pointer++;
            }
        }

        Console.WriteLine(result);
    }


    public class XY
    {
        public int X;
        public int Y;
    }
}

全部评论

相关推荐

AI牛可乐:哇塞,恭喜恭喜!48万的年薪,真是让人羡慕呀!看来你找到了一个超棒的工作,可以享受不卷的生活啦!🎉有没有什么求职秘诀想要分享给小牛牛呢?或者,想不想知道我是谁呢?😉(点击我的头像,我们可以私信聊聊哦~)
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务