hdu多校第八场 1003 (hdu6659) Acesrc and Good Numbers 数论/打表
题意:
对于某数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 数论/打表的更多相关文章
- 2014 HDU多校弟八场H题 【找规律把】
看了解题报告,发现看不懂 QAQ 比较简单的解释是这样的: 可以先暴力下达标,然后会发现当前数 和 上一个数 的差值是一个 固定值, 而且等于当前数与i(第i个数)的商, 于是没有规律的部分暴力解决, ...
- hdu多校第八场Parentheses Matrix
#include<bits/stdc++.h> using namespace std; ][]; int main() { int t; scanf("%d",&am ...
- hdu多校第十场 1003 (hdu6693) Valentine's Day 贪心/概率
题意: 有许多物品,每个物品有一定概率让女朋友开心.你想让女朋友开心且只开心一次,让你挑一些物品,使得这个只开心一次的概率最大,求最大概率. 题解: 设物品i让女朋友开心的概率为$p_i$ 若你挑选了 ...
- hdu多校第八场 1011 (hdu6667) Roundgod and Milk Tea 二分图匹配
题意: 有若干个班,每个班有些人要喝奶茶,也提供一些奶茶,一人喝一杯,但是自己班的人不能喝自己班的奶茶,求最多能有多少人喝上奶茶. 题解: 典型的二分图匹配问题,学生在左,奶茶在右,学生和非自己班的奶 ...
- hdu多校第八场 1010(hdu6666) Quailty and CCPC 排序/签到
题意: CCPC前10%能得金牌,给定队伍解题数和罚时,问你有没有一个队伍如果向上取整就金了,四舍五入就银了. 题解: 排序后按题意求解即可. #include<iostream> #in ...
- hdu多校第八场 1009 (hdu6665) Calabash and Landlord 计算几何/dfs
题意: 给定两个矩形,输出这两个矩形把平面分成了多少块. 题解: 本来是道计算几何的大讨论,被我生生写成了bfs. 离散化边,注意不重合的边中间要空出来一格,四周也要空出来一圈,然后暴力bfs计算一共 ...
- hdu多校第四场 1003 (hdu6616) Divide the Stones 机智题
题意: 给你重量分别为1到n的n个石头,让你分成重量相等,数量也相等的k组,保证k是n的约数.问你能不能分配,如果能,输出具体的分配方案. 题解: 首先,如果1到n之和不能整除k,那么一定不能如题意分 ...
- 2018 HDU多校第四场赛后补题
2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...
- 2018 HDU多校第三场赛后补题
2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...
随机推荐
- JDK1.8之后的新特性和新接口
接口的旧特性: 就特性下接口中只有: 常量(必须赋值) 抽象方法abstract(和final static private三个关键字冲突) interface Inter { //int a ; / ...
- java中设置http响应头控制浏览器禁止缓存当前文档内容
response.setDateHeader("expries", -1); response.setHeader("Cache-Control", " ...
- Shiro学习(14)SSL
对于SSL的支持,Shiro只是判断当前url是否需要SSL登录,如果需要自动重定向到https进行访问. 首先生成数字证书,生成证书到D:\localhost.keystore 使用JDK的keyt ...
- Dubbo入门到精通学习笔记(十六):Keepalived+Nginx实现高可用Web负载均衡
文章目录 Keepalived+Nginx实现高可用Web负载均衡 Keepalived+Nginx实现高可用Web负载均衡 高可用架构篇 Keepalived + Nginx 实现高可用 Web 负 ...
- Dubbo入门到精通学习笔记(五):持续集成管理平台之sonarqube代码质量管理平台的介绍与安装
文章目录 SonarQube的介绍 SonarQube的安装 安装简介 详细安装过程 详细使用过程 SonarQube的介绍 SonarQube是一个管理代码质量的开放平台. 可以从七个维度检测代码质 ...
- Haproxy负载均衡/动静分离(haproxy各选项详细解释)
在前端领域做负载均衡,动静分离的程序有很多,比较常用的是nginx和Haproxy,今天就说一下 Haproxy在这两方面的表现,文章参考很多网文写成,再加上自己的实验成果,文中所有解释都经过实际环境 ...
- DNF邀请码开发再开发方案需求
一.原因分析: 1.现实原因:主播粉丝量级有限,一定规模粉丝注册消耗完后无法进 行之后合作 2.主播资源有限,能合作主播数量少 3.直播粉丝真实接近核心用户,但是不能将其有效转化为平台流水 ...
- 从模块到python文件的两种用法
01模块的四种形式 模块 就是从逻辑上组织python代码(变量,函数,类,逻辑:实现一个功能),本质就是.py结尾的python文件(文件名是test.py的话,它的对应模块名就是test) 包 用 ...
- [POI2011]IMP-Party
题目 不难发现\(\frac{2}{3}n-\frac{1}{3}n=\frac{1}{3}n\)(雾 一个团要求点之间两两有边,于是我们枚举两个点,如果这两个点之间没有边相连,那么就删掉这两个点,由 ...
- 【单调队列优化】[CF372C] Watching Fireworks is Fun
突然发现我可能单调队列都打不来了...我太菜了... 这道题显然有$$f[i][j]=min\{f[i-1][k]+\vert j-a[i] \vert\}$$ 则$ans=\sum_{i=1}^{m ...