QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓

#17875. 构造硬币集合

統計

找零问题是指在商店购买商品后,寻找凑齐需要找零的金额所需的最少硬币数量的问题。硬币系统(coin set)是指可用于找零的一组硬币面值的集合。针对找零问题的贪心算法会不断选择硬币系统中不超过剩余找零金额的最大硬币面值。这个过程一直持续,直到凑齐总找零金额。

最优解是指使用硬币数量最少的方案。然而,贪心算法并不总是能保证得到最优解。在某些情况下,贪心算法可能会给出非最优解。

给定一个正整数 $N$,你的任务是找到一个硬币系统,使得贪心算法对于从 $1$ 韩元到 $(N - 1)$ 韩元的所有金额都能返回最优解,但对于 $N$ 韩元却不能。注意,面值为 $1$ 的硬币必须始终在硬币系统中。

输入格式

输入的第一行包含测试用例的数量 $T$。接下来的 $T$ 行中,每行包含一个整数 $N$。

输出格式

对于每个测试用例:

如果无法构造满足问题给定条件的硬币系统,输出 -1

如果可以构造硬币系统,第一行输出硬币系统的大小 $K$。第二行输出硬币面值 $a_1, a_2, \dots, a_K$,按升序排列,中间用空格分隔。硬币系统的大小不要求最小。

数据范围

  • $1 \le T \le 1000$
  • $1 \le N \le 10^9$
  • $1 \le K \le 30$
  • $1 = a_1 < a_2 < \dots < a_K \le 10^9$

样例

输入样例 1

2
6
3

输出样例 1

3
1 3 4
-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.