QOJ.ac

QOJ

시간 제한: 1.0 s 메모리 제한: 256 MB 총점: 100

#16966. 我的错

통계

一个逻辑电路通过各种门电路将输入映射到输出,且电路中没有反馈回路。输入和输出是一组有序的逻辑值,在此用 0 和 1 表示。我们考虑的电路包括:与门(and,仅当两个输入均为 1 时输出 1)、或门(or,当一个或两个输入为 1 时输出 1)、异或门(xor,仅当两个输入中恰好有一个为 1 时输出 1)和非门(not,输出其单个输入的反转值)。下图展示了两个电路。

图 1:包含 2 个门电路的电路图

图 2:包含 4 个门电路的电路图

不幸的是,真实的门电路有时会发生故障。尽管故障可能以许多不同的方式发生,但本题仅考虑以下三种故障方式: 1) 总是反转正确的输出(即原本输出 0 则变 1,原本输出 1 则变 0); 2) 总是输出 0(恒置 0); 3) 总是输出 1(恒置 1)。 在本题的电路中,最多只有一个门电路会发生故障。

你必须编写一个程序,分析一个电路以及若干对其输入和输出的观测记录,以判断该电路是工作正常还是工作异常。如果至少有一组输入产生了错误的输出,你的程序还必须尝试确定唯一发生故障的门电路以及该门电路的故障方式。这并不总是可行的。

输入格式

输入包含多个测试用例,每个测试用例代表一个电路及其输入和输出的描述。每个测试用例按顺序包含以下部分:

  1. 一行包含三个正整数,分别表示电路的输入端数量 $N$ ($N \le 8$)、门电路数量 $G$ ($G \le 19$) 和输出端数量 $U$ ($U \le 19$)。
  2. 接下来的 $G$ 行,每行对应一个门电路。第一行描述门电路 $g_1$。如果有多个门电路,下一行描述 $g_2$,依此类推。每行包含门电路的类型(a = 与门,n = 非门,o = 或门,x = 异或门),以及该门电路输入端的标识。门电路的输入来自电路的输入端(i1, i2, ...)或其他门电路的输出(g1, g2, ...)。
  3. 一行包含连接到 $U$ 个输出端 $u_1, u_2, \dots$ 的门电路编号。例如,如果有三个输出端,且 $u_1$ 来自 $g_5$,$u_2$ 来自 $g_1$,$u_3$ 来自 $g_4$,则该行内容为:5 1 4
  4. 一行包含一个整数,表示对电路行为的观测记录数量 $B$。
  5. 最后 $B$ 行,每行包含 $N$ 个值(0 或 1)表示观测到的输入值,以及 $U$ 个值表示对应的观测输出值。任意两条观测记录的输入值都不相同。

输入中任何一行的连续项之间都用单个空格分隔。输入以包含三个零的一行结束。

输出格式

对于输入中的每个电路,打印其用例编号(从 1 开始),后跟一个冒号和一个空格,然后是电路分析结果,结果应为以下之一(其中 # 替换为相应的门电路编号):

  • No faults detected
  • Gate # is failing; output inverted
  • Gate # is failing; output stuck at 0
  • Gate # is failing; output stuck at 1
  • Unable to totally classify the failure

图 1 和图 2 中所示的电路分别用于第一个和最后一个样例测试用例。

样例

样例输入 1

2 2 1
o i1 i2
n g1
2
2
1 0 0
0 0 1
2 1 1
a i1 i2
1
1
1 0 1
2 1 1
a i1 i2
1
2
1 0 1
1 1 1
1 1 1
n i1
1
2
1 1
0 0
3 4 4
n g4
a i1 i2
o i2 i3
x i3 i1
2 3 4 1
4
0 1 0 0 1 0 1
0 1 1 0 1 1 0
1 1 1 0 1 0 1
0 0 0 0 0 0 1
0 0 0

样例输出 1

Case 1: No faults detected
Case 2: Unable to totally classify the failure
Case 3: Gate 1 is failing; output stuck at 1
Case 4: Gate 1 is failing; output inverted
Case 5: Gate 2 is failing; output stuck at 0

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.