QOJ.ac

QOJ

حد الوقت: 2.0 s حد الذاكرة: 512 MB مجموع النقاط: 100

#12541. 困难重构

الإحصائيات

Helen 发现了一段使用了大量“魔数”的代码。她发现了一个逻辑表达式,用于检查整数 $x$ 是否属于某一组范围,如下所示:

x >= 5 && x <= 10 ||
x >= 7 && x <= 20 ||
x <= 2 ||
x >= 21 && x <= 25 ||
x >= 8 && x <= 10 ||
x >= 100

Helen 不喜欢“魔数”,因此她决定重构这个表达式以及所有类似的表达式,使得重构后的表达式对于所有整数 $x$ 仍具有相同的布尔结果,但其文本中使用的整数常量尽可能少。

本题中的整数(包括整数 $x$)取值范围为所有 16 位有符号整数,即从 $-2^{15}$ ($-32\,768$) 到 $2^{15} - 1$ ($32\,767$)(包含边界)。

输入格式

输入文件包含最多 1000 行。每一行由一个比较运算,或由逻辑与运算符 && 连接的两个比较运算组成。每个比较运算以 x 开头,后跟大于等于运算符 >= 或小于等于运算符 <=,再后跟一个整数常量。当一行中有两个比较运算时,第一个总是大于等于,第二个总是小于等于。

除最后一行外,所有行均以逻辑或运算符 || 结尾。行内所有标记(token)均由单个空格分隔,且没有行首或行尾空格。

输出格式

将重构后的表达式以与输入相同的格式写入输出文件。你可以按任意顺序排列行,只要最终的表达式格式正确,对所有整数 $x$ 产生相同的布尔结果,并且其文本中包含的整数常量数量最少即可。数字必须格式化为不带前导零的形式,且行内标记之间必须恰好有一个空格。

如果表达式对所有整数均为真,则输出一行 true。如果表达式对所有整数均为假,则输出一行 false

样例

样例输入 1

x >= 5 && x <= 10 ||
x >= 7 && x <= 20 ||
x <= 2 ||
x >= 21 && x <= 25 ||
x >= 8 && x <= 10 ||
x >= 100

样例输出 1

x <= 2 ||
x >= 5 && x <= 25 ||
x >= 100

样例输入 2

x >= 10 && x <= 0

样例输出 2

false

样例输入 3

x <= 10 ||
x >= 0

样例输出 3

true

样例输入 4

x >= -32768

样例输出 4

true

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.