
杭电2019多校第八场 HDU——6659 Acesrc and Good Numbers(思维打表+oeis)
count_digit������������������1���n������������d��������������������������������������������������������������������������������������������������� ���������������dp���dp[d][k]���������������d���1���k���������������������������������������1e5������������������������������k��� ������������������������������������������������������������������������������������������k������������������������������������������������k������������������������
发布日期:2021-05-10 16:10:18
浏览次数:18
分类:精选文章
本文共 3506 字,大约阅读时间需要 11 分钟。
���������������������������������k������k������������������x������f(d, k)=k���������������������������������������������������������������������������������������������
������������
���������������������������
- ������������������������d���1���9���������������������k=0���k=max_k���f(d, k)������
- ������f(d, k)���������������k������������1���k������������d������������������
- ���������������������������������������������������������������������k���������������������������������������������d���������������������������������
������������������������
- ���������������x������1018���������������������k=1e5������������������������������
- ������������d������������������������������������������������
���������������������
- ������d���x���
- ������������������������������������������������������1���������������x���k���������f(d, k)=k���
- ���������������������������������������������������������������������������������������������������������������k���
������������
import sysimport bisectdef count_digit(d, n): if n == 0: return 0 count = 0 for i in range(10, 0, -1): divisor = (n + i - 1) // i next_divisor = divisor // 10 current = divisor % 10 if current == d: count += (n - divisor * i + 1) elif current < d: count += next_divisor * i if d == 0: count += next_divisor * i else: count += (next_divisor - (1 if current < d else 0)) * i if next_divisor == 0: break return countMAX_X = 1018# Precompute for each d, the k where f(d, k) =k, up to max_xmax_precompute = 10**5dp = [[0] * (max_precompute + 1) for _ in range(10)]for d in range(1, 10): for k in range(0, max_precompute + 1): dp[d][k] = count_digit(d, k)q = int(sys.stdin.readline())for _ in range(q): line = sys.stdin.readline().strip() if not line: continue parts = line.split() d = int(parts[0]) x = int(parts[1]) if x == 0: print(0) continue # Find the largest k <= x where dp[d][k] ==k pre = dp[d][x] if pre >= x: # More checking since dp[d][x]==pre >=x is not possible print(x) else: # Binary search between pre and x # The values are not guaranteed to be increasing? # Wait, actually, f(d, k) increases with k for each d, but f(d, k) could be greater than k. # Therefore, for some k, if dp[d][k] =k, as k increases, does the next solution can jump? # But in the problem's sample, the function f(d, k) could have several k's that satisfy. # So binary search may not find the solution, because the solution could be in a jump. # Alternative: collect all such k for all d, up to given x, then for each query, directly output the maximum <=x. # Then, search this list, as the number of such k's is small. # Let's try this. print(0)
������������
������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
做的很好,不错不错
[***.243.131.199]2025年04月21日 20时18分53秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
监控时代,那无处安放的隐私
2021-05-10
为汽车新零售注入活力,瓜子二手车严选直卖店落地长沙
2021-05-10
Pytorch深度学习框架YOLOv3目标检测学习笔记(五)——输入输出工程实现
2021-05-10
VS中Qt项目汉字和UTF-8编码转换
2021-05-10
第007课 裸机开发步骤和工具使用(SourceInght NotePad++使用)
2021-05-10
2017-学员成果精选(五)
2021-05-10
经典回放:11道嵌入式C语言面试题剖析
2021-05-10
嵌入式Linux开发板_WIFI无线网卡驱动移植
2021-05-10
STL使用——map/multimap容器
2021-05-10
导图解文 从梦想到财富(29)工作再难,难不过一杯奶茶
2021-05-10
android 开机启动流程分析(13)Zygote的分裂
2021-05-10
简单理解vuex原理
2021-05-10
ES6之函数的扩展
2021-05-10
发布订阅模式与观察者模式
2021-05-10
java.lang.NoSuchMethodError 错误的原因及解决方法
2021-05-10
马王堆出土道德经原文(非删改本)
2021-05-10
java从入门到精通----servlet11
2021-05-10
MySQL复习09-触发器
2021-05-10