QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 256 MB 満点: 100

#5319. 通用问答系统

統計

每个学生都需要通过提问来获取新知识。调查显示,一些类似的问题会被频繁重复。因此,开发一个自动问答系统来回答这些问题将非常有帮助。你的算法不应预设任何先验知识,但必须能够阅读句子并记住其中提到的事实。每当系统被问及关于此类事实的问题时,它必须能够正确回答。

输入格式

输入包含多个对话。 第一行包含一个正整数 $T$ ($T \le 500$,但请注意其中 95% 的数据规模较小),表示后续对话的数量。每个对话包含一行或多行。每一行包含一个句子:要么是陈述句,要么是疑问句。陈述句以句号 (.) 结尾,而疑问句以问号 (?) 结尾。每个对话后会有一行额外的行,该行以感叹号 (!) 结尾。陈述句和疑问句的定义将在后文讨论。

句子可以包含单词、空格和标点符号。所有单词仅包含拉丁字母,且区分大小写。与常规英语书写规则不同,句子的首字母应保持小写,除非该单词本身的首字母应为大写。单词之间没有多余的空格。没有任何单词超过 10 个字符。每个对话最多有 1000 行。

陈述句

每个陈述句具有以下形式之一: noun_phrase are noun_phrase. noun_phrase can verb_phrase. everything which can verb_phrase can verb_phrase. everything which can verb_phrase are noun_phrase.

noun_phraseverb_phrase 均为单个单词。这四种形式的含义如下:

  • A are B: 如果 $X$ 是 $A$,则 $X$ 是 $B$。
  • A can B: 如果 $X$ 是 $A$,则 $X$ 具有 $B$ 的能力。
  • everything which can A can B: 如果 $X$ 具有 $A$ 的能力,则 $X$ 具有 $B$ 的能力。
  • everything which can A are B: 如果 $X$ 具有 $A$ 的能力,则 $X$ 是 $B$。

疑问句

每个疑问句具有以下形式之一: are noun_phrase noun_phrase? can noun_phrase verb_phrase? can everything which can verb_phrase verb_phrase? are everything which can verb_phrase noun_phrase?

它们是上述陈述句的疑问形式。

在每个测试用例中,不同 noun_phrase 的数量不超过 100;不同 verb_phrase 的数量不超过 100。

输出格式

对于每个测试用例,输出两行。第一行描述从 1 开始计数的测试用例编号,第二行包含的字符数与该测试用例中的问题数量相同。每个字符要么是 'Y'(表示你可以从逻辑上推导出该事实),要么是 'M'(表示不能),不带引号。

样例

输入 1

1
flies can fly.
flies are insects.
everything which can fly are animals.
are everything which can fly insects?
are flies animals?
can flies eat?
everything which can fly can eat.
can flies eat?
Bye!

输出 1

Case #1:
MYMY

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.