onlinejudge_template.analyzer.simplify module¶
the module to manipulate mathematical expressions (e.g. 2 * n + 1
, a_i + i
)
この module は数式を簡約します。
たとえば (n + 1) + (n - 1)
という式が与えられれば 2 * n
という式に簡約して返します。
これは選言標準形のようなものを構成して並べ替えることによって実装されています。
中心部分では、次のような競技プログラミングの問題を解いています:
変数 x, y, z および整数と四則演算と括弧からなる数式が与えられます。
この数式と等しい数式であって $\sum k_i x^{a_i} y^{b_i} z^{c_i}$ という形のものを求めてください。
-
onlinejudge_template.analyzer.simplify.
evaluate
(s: NewType.<locals>.new_type, *, env: Mapping[NewType.<locals>.new_type, Union[int, List[int], List[List[int]], List[List[List[int]]]]] = {}) → Optional[int][source]¶ evaluate converts the given expr to an integer.
-
onlinejudge_template.analyzer.simplify.
format_subscripted_variable
(*, name: str, indices: List[str]) → str[source]¶ format_subscripted_variable constructs a single expr from a variable name and indices
Raises: ExprParserError – if not a variable
-
onlinejudge_template.analyzer.simplify.
parse_subscripted_variable
(s: str) → Tuple[str, List[str]][source]¶ parse_subscripted_variable is an inverse of format_subscripted_variable.
Raises: ExprParserError – if not a variable
-
onlinejudge_template.analyzer.simplify.
rename_variables_in_expr
(expr: NewType.<locals>.new_type, *, replace: Dict[NewType.<locals>.new_type, NewType.<locals>.new_type]) → NewType.<locals>.new_type[source]¶ Raises: ExprParserError –