题意:

对于某数k,若数字d在1-k中出现次数恰好为k,则称k为好数。

给定d,x,求x以内,对于d而言最大的好数。k范围1e18.

题解:

打表二分即可。

但是,1e18的表是没法打出来的,只能在oeis.org上查出来

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<stack>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
using namespace std;
#define INF 0x3f3f3f3f
#define MAXN 100000+50
#define MAXM 30000
#define ll long long
#define per(i,n,m) for(int i=n;i>=m;--i)
#define rep(i,n,m) for(int i=n;i<=m;++i)
#define mod 1000000000 + 7
#define mian main
#define mem(a, b) memset(a, b, sizeof a)
#ifndef ONLINE_JUDGE
#define dbg(x) cout << #x << "=" << x << endl;
#else
#define dbg(x)
#endif
inline int read()
{
int x = , f = ;
char ch = getchar();
while (ch < '' || ch > '')
{
if (ch == '-')
f = -;
ch = getchar();
}
while (ch >= '' && ch <= '')
{
x = * x + ch - '';
ch = getchar();
}
return x * f;
}
inline ll readll()
{
ll x = , f = ;
char ch = getchar();
while (ch < '' || ch > '')
{
if (ch == '-')
f = -;
ch = getchar();
}
while (ch >= '' && ch <= '')
{
x = * x + ch - '';
ch = getchar();
}
return x * f;
}
ll a1[] = { ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, };
ll a2[] = { ,, , , , , , , , , , , , };
ll a3[] = { , ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,};
ll a4[] = { , ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,};
ll a5[] = { , , , , };
ll a6[] = { ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, };
ll a7[] = { ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, };
ll a8[] = { ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, };
ll a9[] = { , , , , , , , , };
int main()
{
int _ = read();
int cnt1 = ;
int cnt2 = , cnt3 = , cnt4 = , cnt5 = , cnt6 = , cnt7 = , cnt8 =, cnt9 = ;
while (_--)
{
int n = read();
ll x = readll();
if (n == )
{
ll pos;
for (int i = ; i < cnt1; ++i)
{
if (a1[i] <= x) pos = a1[i];
}
printf("%lld\n", pos);
}
else if (n == )
{
ll pos;
for (int i = ; i < cnt2; ++i)
{
if (a2[i] <= x) pos = a2[i];
}
printf("%lld\n", pos);
}
else if (n == )
{
ll pos;
for (int i = ; i < cnt3; ++i)
{
if (a3[i] <= x) pos = a3[i];
}
printf("%lld\n", pos);
}
else if (n == )
{
ll pos;
for (int i = ; i < cnt4; ++i)
{
if (a4[i] <= x) pos = a4[i];
}
printf("%lld\n", pos);
}
else if (n == )
{
ll pos;
for (int i = ; i < cnt5; ++i)
{
if (a5[i] <= x) pos = a5[i];
}
printf("%lld\n", pos);
}
else if (n == )
{
ll pos;
for (int i = ; i < cnt6; ++i)
{
if (a6[i] <= x) pos = a6[i];
}
printf("%lld\n", pos);
}
else if (n == )
{
ll pos;
for (int i = ; i < cnt7; ++i)
{
if (a7[i] <= x) pos = a7[i];
}
printf("%lld\n", pos);
}
else if (n == )
{
ll pos;
for (int i = ; i < cnt8; ++i)
{
if (a8[i] <= x) pos = a8[i];
}
printf("%lld\n", pos);
}
else if (n == )
{
ll pos;
for (int i = ; i < cnt9; ++i)
{
if (a9[i] <= x) pos = a9[i];
}
printf("%lld\n", pos);
}
}
}

下面补充关于此题的一个定理证明。

好数不会超过1e11

证明:记f(d,k)为1-k中数字d出现的次数,记g(d,k)=f(d,k)-k

由于对于d=1-9 已经有g(d,1e11-1)=1e10+1

因此对于任意k>1e11 有g(d,k+1e10)-g(d,k)>=1e10(考虑数的后缀是如何组成的)

通俗来讲,在1e11以后,数字d已经比数k多太多了,d再多也追不上了

可以考虑分块,维护数字的后缀信息,以加速打表。

hdu多校第八场 1003 (hdu6659) Acesrc and Good Numbers 数论/打表的更多相关文章

  1. 2014 HDU多校弟八场H题 【找规律把】

    看了解题报告,发现看不懂 QAQ 比较简单的解释是这样的: 可以先暴力下达标,然后会发现当前数 和 上一个数 的差值是一个 固定值, 而且等于当前数与i(第i个数)的商, 于是没有规律的部分暴力解决, ...

  2. hdu多校第八场Parentheses Matrix

    #include<bits/stdc++.h> using namespace std; ][]; int main() { int t; scanf("%d",&am ...

  3. hdu多校第十场 1003 (hdu6693) Valentine's Day 贪心/概率

    题意: 有许多物品,每个物品有一定概率让女朋友开心.你想让女朋友开心且只开心一次,让你挑一些物品,使得这个只开心一次的概率最大,求最大概率. 题解: 设物品i让女朋友开心的概率为$p_i$ 若你挑选了 ...

  4. hdu多校第八场 1011 (hdu6667) Roundgod and Milk Tea 二分图匹配

    题意: 有若干个班,每个班有些人要喝奶茶,也提供一些奶茶,一人喝一杯,但是自己班的人不能喝自己班的奶茶,求最多能有多少人喝上奶茶. 题解: 典型的二分图匹配问题,学生在左,奶茶在右,学生和非自己班的奶 ...

  5. hdu多校第八场 1010(hdu6666) Quailty and CCPC 排序/签到

    题意: CCPC前10%能得金牌,给定队伍解题数和罚时,问你有没有一个队伍如果向上取整就金了,四舍五入就银了. 题解: 排序后按题意求解即可. #include<iostream> #in ...

  6. hdu多校第八场 1009 (hdu6665) Calabash and Landlord 计算几何/dfs

    题意: 给定两个矩形,输出这两个矩形把平面分成了多少块. 题解: 本来是道计算几何的大讨论,被我生生写成了bfs. 离散化边,注意不重合的边中间要空出来一格,四周也要空出来一圈,然后暴力bfs计算一共 ...

  7. hdu多校第四场 1003 (hdu6616) Divide the Stones 机智题

    题意: 给你重量分别为1到n的n个石头,让你分成重量相等,数量也相等的k组,保证k是n的约数.问你能不能分配,如果能,输出具体的分配方案. 题解: 首先,如果1到n之和不能整除k,那么一定不能如题意分 ...

  8. 2018 HDU多校第四场赛后补题

    2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...

  9. 2018 HDU多校第三场赛后补题

    2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...

随机推荐

  1. 【leetcode】133. Clone Graph

    题目如下: Given the head of a graph, return a deep copy (clone) of the graph. Each node in the graph con ...

  2. leetcood学习笔记-28-KMP*

    题目: 第一次提交: class Solution: def strStr(self, haystack: str, needle: str) -> int: if not len(needle ...

  3. Magento站点优化方案

    Magento 是一个开源电子商务系统,尤其以扩展性高著称,但是很高的扩展性往往是牺牲了速度为代价的,虽然现在magento为速度提升做了很多工作,但是还是没能达到人们对速度的要求.既然如此还是很自然 ...

  4. Vue学习笔记【14】——自定义指令

    1.自定义全局和局部(私有)自定义指令 // 自定义全局指令 v-focus,为绑定的元素自动获取焦点: ​ Vue.directive('focus', { ​ inserted: function ...

  5. (转载)js引擎的执行过程(二)

    概述 js引擎执行过程主要分为三个阶段,分别是语法分析,预编译和执行阶段,上篇文章我们介绍了语法分析和预编译阶段,那么我们先做个简单概括,如下: 语法分析: 分别对加载完成的代码块进行语法检验,语法正 ...

  6. Robot Framework:日志输出中文Unicode编码

    robotframework 输出日志时,中文显示为Unicode编码 . 修改方法: 在Python27\Lib\site-packages\robotframework-3.0.4-py2.7.e ...

  7. 八年技术加持,性能提升10倍,阿里云HBase 2.0首发商用

    摘要: 早在2010年开始,阿里巴巴集团开始研究并把HBase投入生产环境使用,从最初的淘宝历史交易记录,到蚂蚁安全风控数据存储,HBase在几代阿里专家的不懈努力下,已经表现得运行更稳定.性能更高效 ...

  8. 思维+双指针+环——cf1244F

    /* 可以发现一个性质:连续两个相同色块永远不会变色 继而可以发现,这个色段每次迭代都向左向右拓展长度1,直到撞上其他扩张的色段 所以预处理出所有连续色段,然后对于所有不在色段里的点,我们可以预测其最 ...

  9. 管理员技术(四): 配置NTP网络时间客户端、 创建一个备份包、 配置用户和组账号、配置一个cron任务

    一. 配置NTP网络时间客户端 目标: 本例要求配置虚拟机 server0,能够自动校对系统时间.相关信息如下: 1> NTP服务器位于 classroom.example.com        ...

  10. wmic命令用法小例

    wmic就是wmic.exe,位于windows目录底下,是一个命令行程序.WMIC可以以两种模式执行:交互模式(Interactive mode)和非交互模式(Non-Interactive mod ...