QOJ.ac

QOJ

时间限制: 4 s 内存限制: 2048 MB 总分: 100

#5133. 不完美的帝国单位

统计

你正在为 Beta 天文学物理会议撰写一篇关于你最近发现灰洞(grey hole)的论文。你的一位合作者进行了大量的测量,你希望通过分析这些数据来得出一些结论。唯一的问题是:数据是在各种各样的单位中测量的,令你感到厌恶的是,它们似乎混合使用了英制和公制系统。为了简化分析,你需要将所有这些测量结果转换为不同的单位。

灰洞的假彩色图像。CC BY 4.0 欧洲南方天文台,修改版

输入格式

输入包含:

  • 一行包含两个整数 $n$ 和 $q$ ($1 \le n \le 100, 1 \le q \le 10\,000$),分别表示单位换算方程的数量和需要回答的查询数量。
  • $n$ 行,每行定义一个单位换算,格式为 “1 = ”。
  • $q$ 行,每行包含一个查询,格式为 “ to ”。

在这些格式中,“” 是一个浮点数 $v$ ($0.001 \le v \le 1000$,小数点后最多 9 位),“” 是一个最多 20 个英文字母(a-z)的字符串。查询中的单位保证在至少一个单位换算方程中定义过。每两个单位之间最多只有一种转换方式。

输出格式

对于每个查询,输出转换后的单位数值,如果无法回答该查询,则输出 “impossible”。

你的答案的相对误差应不超过 $10^{-6}$。

样例

输入格式 1

4 3
1 foot = 12 inch
1 yard = 3 foot
1 meter = 100 centimeter
1 centimeter = 10 millimeter
750 millimeter to meter
42 yard to inch
10 meter to foot

输出格式 1

0.75
1512
impossible

输入格式 2

4 3
1 fortnight = 14 day
1 microcentury = 0.036525 day
1 microcentury = 1000 nanocentury
1 week = 7 day
22.2 fortnight to nanocentury
2.5 nanocentury to week
3.14 day to fortnight

输出格式 2

8509240.2464065708427
1.3044642857142857142e-05
0.22428571428571428572

输入格式 3

10 2
1 micrometer = 1000 nanometer
1 millimeter = 1000 micrometer
1 meter = 1000 millimeter
1 kilometer = 1000 meter
1 megameter = 1000 kilometer
1 lightsecond = 299.792458 meter
1 lightminute = 60 lightsecond
1 lighthour = 60 lightminute
1 lightday = 24 lighthour
1 lightyear = 365.25 lightday
42 nanometer to lightyear
42 lightyear to nanometer

输出格式 3

4.439403502903384947e-18
3.9735067984839359997e+20

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.