编程介的小学生 2017-05-13 16:36 采纳率: 20.5%
浏览 918
已采纳

Equation

Description

A few years ago Nick learned set theory, and liked it so much that sets became the subject of his bachelor’s thesis. Nick’s thesis describes a new kind of mathematical equations — set equations. Set equations are composed of set variables, which represent various subsets of a universal set Ω. The following four operations are defined for set variables:

Intersection ∩: A ∩ B := {x : x ∈ A ∧ x ∈ B}

Union ∪: A ∪ B := {x : x ∈ A ∨ x ∈ B}

Difference −: A − B := {x : x ∈ A ∧ x ∉ B}

Symmetric difference ⊕: A ⊕ B := (A − B) ∪ (B − A)

The operations are listed in the order of their precedence, i.e. intersection has the highest precedence, union has lower precedence than intersection, difference has lower precedence than union, and symmetrical difference has the lowest precedence. Parentheses can be used to change operations precedence as usual.

The thesis includes a chapter dedicated to automated solving of some specific classes of set equations. Nick has already elaborated a notation for storing equations in text files. Here is some quotation from the thesis:

The following notation is used for describing set equations:

‹space or tab› → space | tabulation symbol
‹ws› → ‹space or tab› ∗
‹char› → ‘A’ | ‘B’ | … | ‘Z’ | ‘a’ | ‘b’ | … | ‘z’
‹var› → ‹char› ‹char› ∗
‹expr› → ‹var›
| ‹expr› ‹ws› ‹operator› ‹ws› ‹expr›
| ‘(’ ‹ws› ‹expr› ‹ws› ‘)’
‹operator› → ‘+’ | ‘-’ | ‘*’ | ‘^’
‹equation› → ‹expr› ‹ws› ‘=’ ‹ws› ‹expr›
Operators ∪, ∩, − and ⊕ are encoded with tokens ‘+’, ‘*’, ‘-’ and ‘^’ respectively. The ‘=’ token denotes the operator of set equality.

It is possible to assign values to some variable using the following notation:

‹digit› → ‘0’ | ‘1’ | … | ‘9’
‹element› → ‹digit› ∗
‹variable value› → ‹var› ‹ws› ‘=’ ‹ws› ‹values›
‹values› → ‹element›
| ‹element› ‹space or tab› ‹ws› ‹values›
Unfortunately Nick is not very skilled in programming so he asks you to help and write a program module for automated solving of one specific simple class of equations — the equations where each variable, except Ω, occurs exactly one time.

Input

Input file is written in Nick’s notation.

The first line of the input file contains an equation to solve. Total length of the equation does not exceed 1 000 characters. There is exactly one occurrence of each variable, except “Omega”, in the equation.

The following lines contain definitions of variable values. Variable name lengths do not exceed ten characters each. There is always a variable called “Omega” that represents the universal set. Both the number of elements in the universal set and the value of each element does not exceed 500.

The total length of all variable definitions does not exceed 100 000 characters.

Output

First line of the output file must contain “Solution” if there exists at least one solution of the given equation and “No Solution” otherwise.

If the solution exists the following lines must contain such values of all undefined variables so that equation is satisfied. The variables may be listed in arbitrary order.

Sample Input

#1 Omega - OneOrThree = Two
Omega = 1 2 3
Two = 2
#2 Omega * result * result = Empty
Omega = 1 2 3 4 5
Empty =
#3 (one+two) ^(TWO+three) = result
one =1
TWO =1 3 4 5
two =2
three=3
Omega=1 2 3 4 5
result = 2 3 4 5
#4 Omega ^Omega = Omega
Omega=123 234 345 456
Sample Output

#1 Solution
OneOrThree = 1 3
#2 Solution
Result=
#3 Solution
#4 No Solution

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-05-31 02:54
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来