QOJ.ac

QOJ

时间限制: 1 s 内存限制: 256 MB 总分: 100

#8470. 深渊

统计

Kieray 有一个哈希函数 $h(x)$。她希望你帮她找到 $h$ 的一个不动点 $x_0$,使得 $h(x_0) = x_0$。

输入格式

输入包含对 $h(x)$ 的描述。

函数 $h(x)$ 由 Frog 语言编写的程序描述。在该语言中,变量(例如 $x, y, z$)均为 128 位无符号整数。程序开始时,变量 $x$ 包含输入给 $h$ 的值,其他变量均初始化为零。$h(x)$ 的结果是程序执行完毕后变量 $x$ 的值。

该程序最多包含 500 行。每一行都是一个赋值语句,将表达式的结果存储到变量中。Frog 语言支持按位取反(~)、与(&)、或(|)、异或(^)以及左移/右移(<< / >>)。这些操作的语义与 C/C++ 中的类似。

每个赋值语句最多包含一个二元运算。(十六)进制常量可以在表达式中使用。按位取反(~)对每个变量或常量最多只能应用一次。除按位异或表达式(^)外,每个表达式最多包含一个变量。移位操作的移位量(右操作数)是非负的且不超过 128。

以下是 Frog 语言的扩展 BNF 规范:

Newline = "\n"
DecimalDigit = "0" ... "9"
HexDigit = "0" ... "9" | "a" ... "f"
Letter = "a" ... "z"
Hexadecimal = "0" "x" HexDigit{1,32}
Variable = Letter{1,4}
Term = ("~" | ) ( Variable | Hexadecimal )
ConstantTerm = ("~" | ) Hexadecimal
ShiftAmount = DecimalDigit
| ("1" ... "9") DecimalDigit
| "1" ("0" | "1") DecimalDigit
| "1" "2" ("0" ... "8")
Expression = Term
| Term " " "^" " " Term
| Term " " "&" " " ConstantTerm
| ConstantTerm " " "&" " " Term
| Term " " "|" " " ConstantTerm
| ConstantTerm " " "|" " " Term
| Term " " "<<" " " ShiftAmount
| Term " " ">>" " " ShiftAmount
Assignment = Variable " " "=" " " Expression
Procedure = ( Assignment Newline )*

注:“*” 表示前面的标记出现零次或多次,“{1,4}” 表示前面的标记出现一到四次。符号 “␣” 表示单个空格字符。

输出格式

输出 $h(x)$ 的不动点,以十六进制表示,不含前导零,并符合扩展 BNF 规范中 Hexadecimal 的格式。如果存在多个不动点,请输出最小的一个。如果没有不动点,则输出 “:(”(不含引号)。

样例

输入 1

x = x | 0x19260817

输出 1

0x19260817

输入 2

x = x ^ 0xdeadbeef

输出 2

:(

输入 3

y = ~x << 3
z = ~x >> 2
w = x & ~0xa
k = ~x ^ 0xc
k = k << 1
k = k >> 2
x=y^z
p=k^w
x=x^p

输出 3

0x9a83dcd41ee6a0f73507b9a83dcd41ef

输入 4

x = x | 0x1
x = x << 128

输出 4

0x0

说明

这是来自 Kieray 的插图。它很可爱。

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.