QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 64 MB 總分: 100

#2042. 平衡

统计

Ms. Iyo Kiffa-Australis 拥有一台天平和两种砝码,用于测量药物的剂量。

例如,要使用 $300\,\text{mg}$ 和 $700\,\text{mg}$ 的砝码测量 $200\,\text{mg}$ 的阿司匹林,她可以在药物一侧放置一个 $700\,\text{mg}$ 的砝码,在另一侧放置三个 $300\,\text{mg}$ 的砝码(图 1)。虽然她也可以在药物一侧放置四个 $300\,\text{mg}$ 的砝码,在另一侧放置两个 $700\,\text{mg}$ 的砝码(图 2),但她不会选择这种方案,因为使用更多的砝码不太方便。

请你通过计算所需的砝码数量来帮助她。

图 1:使用三个 300mg 砝码和一个 700mg 砝码测量 200mg 阿司匹林

图 2:使用四个 300mg 砝码和两个 700mg 砝码测量 200mg 阿司匹林

输入格式

输入包含一系列数据集。每个数据集占一行,包含三个正整数 $a, b$ 和 $d$,中间用空格隔开。满足以下关系:$a \neq b$,$a \leq 10000$,$b \leq 10000$ 且 $d \leq 50000$。你可以假设一定可以通过 $a\,\text{mg}$ 和 $b\,\text{mg}$ 砝码的组合测量出 $d\,\text{mg}$。换句话说,你不需要考虑“无解”的情况。

输入结束由一行包含三个零的数据表示,该行不属于数据集。

输出格式

输出应包含多行,每一行对应一个输入数据集 $(a, b, d)$。输出行应包含两个非负整数 $x$ 和 $y$,中间用空格隔开。它们应满足以下三个条件:

  • 可以使用 $x$ 个 $a\,\text{mg}$ 砝码和 $y$ 个 $b\,\text{mg}$ 砝码测量出 $d\,\text{mg}$。
  • 在满足上述条件的所有非负整数对 $(x, y)$ 中,砝码总数 $(x + y)$ 最小。
  • 在满足前两个条件的所有非负整数对 $(x, y)$ 中,砝码的总质量 $(ax + by)$ 最小。

输出中不应包含多余的字符(例如多余的空格)。

样例

样例输入 1

700 300 200
500 200 300
500 200 500
275 110 330
275 110 385
648 375 4002
3 1 10000
0 0 0

样例输出 1

1 3
1 1
1 0
0 3
1 1
49 74
3333 1

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.