QOJ.ac

QOJ

Limite de temps : 3 s Limite de mémoire : 1024 MB Points totaux : 100

#15183. Cutting into Monotone Increasing Sequence

Statistiques

单调序列是指在沿着序列移动时,数值持续增加或持续减少的序列。换句话说,它在上升或下降方向上表现出一致的趋势。

在单调递增序列中,序列中的每一项都大于或等于前一项。从数学上讲,对于序列 $a_1, \dots, a_n$,当且仅当对于每个 $1 \le i < n$ 都有 $a_i \le a_{i+1}$ 时,它才是单调递增的。例如,序列 1, 2, 2, 4, 5 是一个单调递增序列,因为每一项都大于或等于前一项。

单调序列在微积分和分析学等多个数学领域中都非常重要,因为它们通常能简化对函数及其行为的分析。它们提供了一种清晰且一致的趋势,使得更容易理解序列或函数在某一数值范围内的行为。

我们的一位命题人非常喜欢大整数。在过去的几年里,台湾网络程序设计竞赛(Taiwan Online Programming Contest)经常出现涉及大整数的题目。这一次,我们带来了一个将大整数与单调递增序列相结合的题目。您的任务是通过在数字之间的间隙中插入逗号 ,,将一个表示为 $x$ 的大整数转换为一个单调递增序列,同时满足以下约束条件:

  • 单调递增序列的最后一项不超过 $b$。
  • 逗号不能插入在数字 0 之前。
  • 逗号的数量最少。

假设 $x$ 是一个具有 $k$ 位数字的整数,表示为 $d_1d_2 \cdots d_k$。例如,如果 $x = 654321 = d_1d_2 \cdots d_6$ 且 $b = 1000$,我们可以在 $d_3$ 和 $d_5$ 之后的间隙中插入逗号,将 $x$ 转换为以下单调递增序列:6, 54, 321。

请编写一个程序,计算将给定的大整数 $x$ 转换为由不超过给定整数 $b$ 的数字组成的单调递增序列所需的最小逗号数量。如果无法进行转换,请输出 NO WAY

输入格式

输入包含两个非负整数 $x$ 和 $b$。

输出格式

输出将 $x$ 转换为由不超过 $b$ 的数字组成的单调递增序列所需的最小逗号数量。如果无法进行转换,请输出 NO WAY(不带引号)。

数据范围

  • $x \le 10^{100000}$
  • $b < 2^{64}$
  • 如果 $x > 0$,则 $x$ 没有前导零。

样例

输入样例 1

654321 1000

输出样例 1

2

输入样例 2

654321 100

输出样例 2

NO WAY

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.