#P7040. [NWRRC2016] Java2016

[NWRRC2016] Java2016

题目描述

John likes to learn esoteric programming languages. Recently he discovered the probabilistic programming language\textit{programming language} Java2K. Built-in functions of Java2K have only a certain probability to do whatever you intend them\textit{intend them} to do.

The Java2K programming is very hard, so John designed a much simpler language for training: Java2016. Built-in\textit{Built-in} operators of Java2016 are deterministic, while their operands are random. Each value in Java2016 is\textit{Java2016 is} a positive integer in the range 02550 \cdots 255 , inclusive.

Java2016 supports six operators of three precedencies:

$$\begin{aligned}{\langle \mathrm{expression}\rangle}&\quad::=\quad{\langle \mathrm{expression}\rangle}\operatorname{`\texttt{min}\text'}{\langle \mathrm{sum}\rangle}\mid{\langle \mathrm{expression}\rangle}\operatorname{`\texttt{max}\text'}{\langle \mathrm{sum}\rangle}\mid {\langle \mathrm{sum}\rangle}\\{\langle \mathrm{sum}\rangle}&\quad::=\quad{\langle \mathrm{sum}\rangle}\operatorname{`\texttt{+}\text'}{\langle \mathrm{term}\rangle}\mid{\langle \mathrm{sum}\rangle}\operatorname{`\texttt{-}\text'}{\langle \mathrm{term}\rangle}\mid{\langle \mathrm{term}\rangle}\\{\langle \mathrm{term}\rangle}&\quad::=\quad{\langle \mathrm{term}\rangle}\operatorname{`\texttt{*}\text'}{\langle \mathrm{factor}\rangle}\mid {\langle \mathrm{term}\rangle}\operatorname{`\texttt{/}\text'}{\langle \mathrm{factor}\rangle}\mid {\langle \mathrm{factor}\rangle}\\{\langle \mathrm{factor}\rangle}&\quad::=\quad\operatorname{`\texttt{(}\text'}{\langle \mathrm{expression}\rangle}\operatorname{`\texttt{)}\text'}\mid `\texttt{?}\text'\mid {\langle \mathrm{macro}\rangle}\end{aligned} $$

Minimum (‘min’)(\textit{`min'}) and maximum ((‘max’))((\textit{`max'})) operators are defined as usual. Addition (‘+’),(\text{`+'}), subtraction (‘–’) and(\text{`--'}) and multiplication (×)(\text{`}\times\text{'}) are defined modulo 256256 . The result of the division (/)(\text{`}/\text{'}) is rounded towards zero. If\textit{If} the divider is zero, the program crashes. The argument of the operator is a result of another operator, evenly\textit{operator, evenly} distributed random value (?)(\text{`}?\text{'}), or macro substitution.

For instance, the probability that ‘?/?/?’\text{`?/?/?'} is evaluated to zero is 98.2%98.2\%, while the probability of the crashthe crash is 0.8%0.8\%.

The Java2016 program consists of zero or more macro definitions, followed by the resulting expression.  Each Each macro definition has a form of

$$\begin{aligned}{\langle \mathrm{macrodef}\rangle}&\quad::=\quad{\langle \mathrm{macro}\rangle}\operatorname{`\texttt{=}\text'}{\langle \mathrm{expression}\rangle}\\{\langle \mathrm{macro}\rangle}&\quad::=\quad\operatorname{`\texttt{a}\text'}\ldots\operatorname{`\texttt{z}\text'}\end{aligned} $$

The macro should be defined before the first use. It may not be redefined. The macro is expanded to its definitionits definitio_n on each use. For instance,

a = ? max ?
(a max $a) / a

is expanded to ((? max ?) max (? max ?)) / (? max ?).

John is going to add probabilistic constants to Java2016, so for each possible constant value he needs a programa progra_m that successfully evaluates to this value with at least one-half probability. Crashes are counted toward\textit{counted toward} failures.

输入格式

The input contains a single integer cc -- the target constant (0c255)(0 \le c \le 255) .

输出格式

Output a Java2016 program that successfully evaluates to constant cc with probability no less than 1/21/2 .  The The total length of the program should not exceed 256256 characters (excluding spaces).

题目大意

John 喜欢学习深奥的编程语言。最近,他发现了概率编程语言 Java2K。Java2K 的内置函数只有一定的概率去执行你想让它们做的事情。

Java2K 编程非常困难,因此 John 设计了一种简单得多的语言用于训练:Java2016。Java2016 的内置运算符是确定性的,而它们的操作数是随机的。Java2016 中的每个值都是 00255255 (包含 00255255) 中的整数。

Java2016 支持分为三个优先级的六种运算符:

$$\begin{aligned}{\langle \mathrm{expression}\rangle}&\quad::=\quad{\langle \mathrm{expression}\rangle}\operatorname{`\texttt{min}\text'}{\langle \mathrm{sum}\rangle}\mid{\langle \mathrm{expression}\rangle}\operatorname{`\texttt{max}\text'}{\langle \mathrm{sum}\rangle}\mid {\langle \mathrm{sum}\rangle}\\{\langle \mathrm{sum}\rangle}&\quad::=\quad{\langle \mathrm{sum}\rangle}\operatorname{`\texttt{+}\text'}{\langle \mathrm{term}\rangle}\mid{\langle \mathrm{sum}\rangle}\operatorname{`\texttt{-}\text'}{\langle \mathrm{term}\rangle}\mid{\langle \mathrm{term}\rangle}\\{\langle \mathrm{term}\rangle}&\quad::=\quad{\langle \mathrm{term}\rangle}\operatorname{`\texttt{*}\text'}{\langle \mathrm{factor}\rangle}\mid {\langle \mathrm{term}\rangle}\operatorname{`\texttt{/}\text'}{\langle \mathrm{factor}\rangle}\mid {\langle \mathrm{factor}\rangle}\\{\langle \mathrm{factor}\rangle}&\quad::=\quad\operatorname{`\texttt{(}\text'}{\langle \mathrm{expression}\rangle}\operatorname{`\texttt{)}\text'}\mid `\texttt{?}\text'\mid {\langle \mathrm{macro}\rangle}\end{aligned} $$

最小 (‘min’\operatorname{`\texttt{min}\text'}) 和最大 (‘max’\operatorname{`\texttt{max}\text'}) 运算符的定义和通常一样。加法 (‘+’\operatorname{`\texttt{+}\text'})、减法 (‘-’\operatorname{`\texttt{-}\text'}) 和乘法 (‘*’\operatorname{`\texttt{*}\text'}) 是在模 256256 的意义下定义的。除法 (/’`\operatorname{\texttt{/}\text'}) 的结果向 00 取整。如果除数是 00,程序就会崩溃。运算符的参数是另一个运算符的结果、均匀分布的随机数 (‘?’\operatorname{`\texttt{?}\text'}) 或宏代换的结果。

例如,?/?/?``\texttt{?/?/?}\text{''}98.2%98.2\% 的概率计算得到 00,而崩溃的概率为 0.8%0.8\%

Java2016 程序由零个或多个宏定义以及随后的结果表达式组成。每条宏定义都形如

$$\begin{aligned}{\langle \mathrm{macrodef}\rangle}&\quad::=\quad{\langle \mathrm{macro}\rangle}\operatorname{`\texttt{=}\text'}{\langle \mathrm{expression}\rangle}\\{\langle \mathrm{macro}\rangle}&\quad::=\quad\operatorname{`\texttt{a}\text'}\ldots\operatorname{`\texttt{z}\text'}\end{aligned} $$

宏必须在第一次使用前被定义。宏不能被重复定义。宏在每次使用时都会被展开成它的定义。例如,

a = ? max ?(a max a) / a\texttt{a = ? max ?}\\\texttt{(a max a) / a}

会被展开成 $``\texttt{((? max ?) max (? max ?)) / (? max ?)}\text{''}$。

John 将要把概率常量加入 Java2016,因此对每个可能的常量,他需要一个程序能以至少一半的概率成功计算出这个值。崩溃被算作失败。

输入

输入包含一个整数 cc (0c2550\le c\le 255),表示目标常量。

输出

输出一个 Java2016 程序,它需要能够以至少 1/21/2 的概率成功计算出常量 cc。程序的总长度不应超过 256256 个字符 (空格不计算在内)。

0

? /?/ ?

1

a = ? max ?
(a max a) / a

提示

Time limit: 2 s, Memory limit: 512 MB.