uva 11724 - Evaluate the Expression(expression)

该问题涉及根据特定的BNF语法解析和评估数学表达式。表达式可以包含变量、操作符(加号或乘号)和括号。计算时需遵循常规运算顺序,即先处理括号内的表达式,再进行乘法,最后做加法。给定一个表达式和一些不等式条件,需要找到一个变量的正整数赋值方案,使得表达式的值最小。如果无法找到满足所有不等式的赋值,输出-1。
摘要由CSDN通过智能技术生成

B

Evaluate the Expression

Input: Standard Input

Output: Standard Output

 

In this problem, we will consider a mathematical expression according to the following BNF grammar:

<expression> = <variable> | <expression><operator><expression>| “(“<expression>“)”
<operator> = “+” | “*”
<variable> = “a” | “b” | “c” | … | “y” | “z”

 

When evaluating such expressions, you have to follow the conventional rules. That means you have to do things in the brackets first and multiplications have to be done before addition.

Example:  2*(3+4*2) = 22

Given an expression and some inequalities, you have to assign each variable with a positive integer so that the value of the expression is minimized.

 

Consider an example:
Expression = a+b*c and Inequalities = a>b,  c>b

 

Assignment of: a=2, b=1 and c=2 will give us the minimum value. => 2 + 1*2 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值