QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 32 MB مجموع النقاط: 10 اختبارات مفتوحة

#11675. 公式

الإحصائيات

正如高地人所说,真理有三种:神圣的真理、也是真理,以及……真理。拜特逻辑学家的最新研究证实了这一点。他们正在研究一种简化形式的逻辑表达式(命题公式),称为子句范式。子句范式的形式如下:

  • 公式由逻辑变量 $x_1, x_2, \ldots, x_n$ 构建。这些变量可以取真或假。
  • 文字是逻辑变量或其否定,即 $x_i$ 或 $\neg x_i$(对于 $1 \le i \le n$)。
  • 子句是文字的合取,例如 $x_4 \wedge \neg x_2 \wedge x_3$。
  • 公式是子句的析取,例如 $(x_1 \wedge \neg x_2) \vee (\neg x_1 \wedge x_3) \vee (\neg x_3)$。

公式的值取决于变量的具体取值。变量的取值由称为赋值的函数确定,形式为 $f : \{1, 2, \ldots, n\} \mapsto \{\text{真}, \text{假}\}$,其中 $f(i)$ 是赋予变量 $x_i$ 的值。所有可能的赋值共有 $2^n$ 种。对于特定的赋值,给定公式的值要么为真,要么为假。

如果一个公式对于每一个赋值其值均为真,则称该公式为真。如果一个公式对于每一个赋值其值均为假,则称该公式为假。通常,公式既不是恒真也不是恒假的,其值实际上取决于给定的赋值。我们可以将公式的真值定义为一个分数(范围从 0 到 1):

$$\frac{\text{使公式值为真的赋值数量}}{2^n}$$

数字 1 对应于恒真公式,0 对应于恒假公式。

样例

公式:

$$(x_1 \wedge \neg x_1) \vee (\neg x_2 \wedge \neg x_3) \vee (x_3 \wedge x_2)$$

在八种可能的赋值中,有四种使该公式为真。因此,它的真值为二分之一。

任务

你拥有 11 组数据。每组数据存储在单独的文件中:fork.in,其中 $k$ 是数据集编号($0 \le k \le 10$)。文件 for0.in 包含符合上述样例的数据。编写一个程序,输入一个整数 $k$($0 \le k \le 10$),并输出一行,包含第 $k$ 组数据中给定公式的近似真值。真值应以十进制分数形式输出,计算精度要求为相对误差 $3\%$。也就是说,如果公式的真值为 $p$,计算出的近似值为 $p'$,则必须满足 $|p' - p| \le 0.03p$。

输入格式

输入的第一行包含两个正整数 $n$ 和 $m$,$1 \le n \le 100$,$1 \le m \le 100$,由单个空格分隔。公式中可能出现的逻辑变量为 $x_1, x_2, \ldots, x_n$。公式由 $m$ 个子句组成,描述在接下来的 $m$ 行中,每行一个子句。每一行包含由单个空格分隔的整数。第一个整数 $l$($1 \le l \le n$)是构成该子句的文字数量。随后是 $l$ 个整数,表示子句中的连续文字。这些数字是非零整数,范围从 $-n$ 到 $n$。数字 $i$(对于 $1 \le i \le n$)表示 $x_i$,数字 $-i$ 表示 $\neg x_i$。

样例

输入 1

0

输出 1

0.5

说明 1

对于样例测试,0.485、0.498、0.51、0.515 也是可接受的答案。

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.