QOJ.ac

QOJ

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

#11241. 找零

الإحصائيات

你目前只有一张面值为 $A$ CNY 的纸币或硬币(CNY 代表人民币,即中华人民共和国的货币单位)。你很快需要在某个地方支付恰好 $B$ CNY。你目前唯一的选择是在自动售货机上消费,该售货机有无限多件商品,价格可以是任何正数。你可以花任意多的时间使用这台自动售货机。然而,你不能对自动售货机找零的方式做任何假设;唯一可以保证的是,它找回的纸币/硬币总额等于应找回的金额。

为了确保之后能够支付恰好 $B$ CNY,你需要在自动售货机上花费的最小总金额是多少?也就是说,在最坏的情况下,为了得到一张面值为 $B$ CNY 的纸币/硬币,或者得到一些面值较小的纸币/硬币并能组合出恰好 $B$ CNY,你必须花费的最小总金额是多少?

在本题中,我们假设所有人民币面值都在使用中,包括 1 分 (0.01 CNY)、2 分、5 分、1 角 (0.1 CNY)、2 角、5 角、1 元 (1 CNY)、2 元、5 元、10 元、20 元、50 元和 100 元。这些是自动售货机接受或找零时仅有的面值。

输入格式

输入的第一行包含测试用例的数量 $T$。接下来有 $T$ 行。 每行包含两个数字 $A$ 和 $B$。

输出格式

对于每个测试用例,输出一行 “Case #x: y”,其中 $x$ 是测试用例编号(从 1 开始),$y$ 是当你只有一张面值为 $A$ CNY 的纸币/硬币且需要支付恰好 $B$ CNY 时,你必须花费的最小金额(单位为 CNY)。

数据范围

  • $1 \le T \le 78$
  • $A, B \in \{0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, 100\}$ 且 $A > B$

样例

输入 1

2
0.05 0.02
2 1

输出 1

Case #1: 0.01
Case #2: 0.01

说明

在 Case #1 中,最优解是购买一件价格为 1 分的商品。机器可能会找回以下任意一种组合:两个 2 分;一个 2 分和两个 1 分;四个 1 分。在所有这些情况下,你要么拥有了所需的 2 分,要么可以将两个 1 分组合起来凑出恰好 2 分的金额。

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.