题意:

对于某数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. Python 十大装 B 语法解析

    Python 是一种代表简单思想的语言,其语法相对简单,很容易上手.不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了.本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并 ...

  2. bootstrap 标签页的使用(tab)

    <!DOCTYPE html> <html> <head> <title></title> <link rel="style ...

  3. linux IPC socket(2)

    使用bind来关联地址和套接字 #include <sys/types.h> #include <sys/socket.h> int bind(int sockfd, cons ...

  4. 自己写的一些Delphi常用函数

    今天在整理以前写过的代码,发现有些函数还是挺实用的,决定将其贴到Blog上,与众多好友一起分享.{*************************************************** ...

  5. Dubbo入门到精通学习笔记(十七):FastDFS集群的安装、FastDFS集群的配置

    文章目录 FastDFS集群的安装 FastDFS 介绍(参考:http://www.oschina.net/p/fastdfs) FastDFS 上传文件交互过程: FastDFS 下载文件交互过程 ...

  6. 前端(十七)—— jQuery基础:jQuery的基本使用、JQ功能概括、JS对象与JQ对象转换、Ajax简单应用、轮播图

    jQuery的基本使用.JQ功能概括.JS对象与JQ对象转换.Ajax简单应用.轮播图 一.认识jQuery 1.什么是jQuery jQuery是对原生JavaScript二次封装的工具函数集合 j ...

  7. Lucene字段

    字段是最低单元或索引过程的起点.它代表其中一个键被用于识别要被索引的值的键值对关系.用于表示一个文件的内容的字段中将具有键为“内容”和值,可以包含文本或文档的数字内容的部分或全部. Lucene可以索 ...

  8. 40-Ubuntu-用户管理-05-which查看命令所在位置

    which 查看执行命令所在的位置 例: 1.查看修改用户密码的命令--passwd所在位置 which passwd 注: /etc/passwd 是用于保存用户信息的文本文件. /usr/bin/ ...

  9. POJ 3469 /// 最大流Dinic

    题目大意: N个模块 在核A上执行花费a[i] 在核B上执行花费b[i] 有M个模块组合(d1,d2) 若d1模块与d2模块在不同核上执行需多花费w[i] 求执行所有模块所需的最小花费 挑战P237 ...

  10. Markdown测试2

    四级标题 内容测试 内容测试 内容测试 为知笔记发布博客时会添加一些HTML或CSS的标记,会影响文章的摘要显示. A B 一 二 α​" role="presentation&q ...