2020牛客暑期多校训练营(第四场)D- Dividing Strings

传送门

Description

With powerful decision-making skills, ZYB can solve complex problems

ZYB has a decimal string {s}s of length {n}n. He wants to split the string into several (at least 2) non-empty continuous substrings and minimize the difference between the maximum value and the minimum value of the gifts. The value of a continuous substring is the value of it when it’s considered as a decimal number.
For instance, when the string ‘1230’ is split into ‘12’ and ‘30’, the values of the two parts are 12 and 30 separately. Notice that the substrings are not allowed to contain leading zero(s). For example, the only feasible way of splitting ‘001’ is ‘0’, ‘0’ and ‘1’.

Can you help ZYB find the fairest splitting?

简洁题意

  • 把一个数字串划成若干段(至少两段),使得最大值和最小值的差尽量的小。注意不能有前导0

一个显然而重要的性质

  • a n s ≤ 9 ans\leq 9 ans9,因为把字符串分成单个数字后数字 x x x必为 0 ≤ x ≤ 9 0\leq x\leq 9 0x9

优化

Case 1
  • 划成的每一段长度相等
  • 因为 N N N 只有 1 0 5 10^5 105,我们可以枚举 N N N 的所有约数。对于给定约数,线性扫一遍判断答案、复杂度 O ( N √ N ) O(N√N) O(NN)(而且跑不到)

Case 2
  • 划成的段里最大段和最小段的长度差为1
  • 答案若要小于 9 9 9,形式只可能是 99 … 9 x 99…9x
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值