QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 512 MB 总分: 100

#9136. 指数计算器

统计

Kirill 想要制作他自己的计算器。然而,他遇到了一个严重的问题——他需要添加能够计算某些复杂函数的按钮。

他的计算器有 16 个寄存器 $\$0, \$1, \dots, \$15$,每个寄存器包含一个 64 位浮点数(双精度浮点格式)。

计算器操作应由使用寄存器的命令序列表示:

  • $\$i = \text{operand1 operation operand2}$
  • $\$i = \text{value}$

在第一种命令中,$\text{operand1}$ 和 $\text{operand2}$ 可以是实数或寄存器之一。至少有一个操作数必须是寄存器,且 $\text{operation}$ 必须是 $+$, $-$, $*$ 之一,分别对应加法、减法和乘法。

在第二种命令中,$\text{value}$ 必须是某个实数(不允许使用寄存器)。

为了计算此操作,寄存器 $\$1$ 的初始值等于 $x$(操作的输入),其他寄存器的初始值等于 $0$。此后,执行所有命令。首先,计算等号右侧的值并将其赋值给左侧的寄存器。操作的输出是寄存器 $\$0$ 的值,其他寄存器的值不予考虑。

请编写一个最多包含 25 条命令的序列,以便对于所有 $x \in [-20, 20]$,都能以良好的精度计算函数 $e^x$($e$ 是欧拉数,即自然对数的底)。

输入格式

你可以将此问题视为一个仅输出答案的问题。 该问题只有一个测试用例,其中包含一个字符串 “input”。

输出格式

第一行包含一个整数 $k$ ($0 \le k \le 25$),表示命令的数量。接下来的 $k$ 行应描述计算 $e^x$ 的命令序列。

接下来的 $k$ 行中的每一行都应包含上述两种格式之一的命令。必须满足上述条件。对于所有寄存器 $\$i$,必须满足 $0 \le i \le 15$。

注意,在本题中,第一行仅用于指定命令数量,且接下来的 $k$ 行中每一行必须恰好包含一个操作(中间不能有空行)。所有操作数、运算符和 $=$ 号都应以空格分隔。

对于所有 $x = \frac{n}{10^5}$(其中 $n$ 为整数,$-2 \cdot 10^6 \le n \le 2 \cdot 10^6$),该命令序列都将被执行。 假设答案为 $y_1 = e^x$,计算出的答案为 $y_2$。如果满足 $\frac{|y_1 - y_2|}{y_1} \le 10^{-9}$,则认为答案正确。

样例

样例输入 1

input

样例输出 1

6
$0 = $0 * $0
$0 = 2.718281828459
$0 = $1 + $0
$15 = 8.1000000737 * $0
$12 = $15 * 0.123456789
$0 = $12 - $1

说明

所提供的答案仅作为示例,且是不正确的。 很容易看出,对于所有 $x$,它只是近似计算了 $e$(因此该答案仅在 $x = 1$ 时正确)。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.