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 ...
随机推荐
- Python 十大装 B 语法解析
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手.不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了.本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并 ...
- FTP的PORT和PASV的连接方式以及数据连接端口号计算
FTP的PORT和PASV的连接方式以及数据连接端口号计算 PORT(自动)方法的连接途中是: 客户端向服务器的FTP端口(原始是21)发送连接请求,服务器领受连接,建立一条command链路. ...
- Vue学习笔记【10】——Vue指令之v-if和v-show
Vue指令之v-if和v-show <!DOCTYPE html> <html lang="en"> <head> <meta cha ...
- PHP ftp_put() 函数
定义和用法 ftp_put() 函数上传本地一个文件到 FTP 服务器上. 如果成功,该函数返回 TRUE.如果失败,则返回 FALSE. 语法 ftp_put(ftp_connection,remo ...
- MyEclipse6.0中使用aptana插件,添加jquery提示功能
MyEclipse6.0中使用aptana插件,添加jquery提示功能 第一:查看当前MyEclipse集成的eclipse的版本,, 查看路径 D:/MyEclipse 6.0/eclips ...
- (转)OpenFire源码学习之十五:插件开发
转:http://blog.csdn.net/huwenfeng_2011/article/details/43418493 Plugin接口规范 插件是openfire功能的增强表现,它的主要任务: ...
- (转)OpenFire源码学习之十一:连接管理(下)
转:http://blog.csdn.net/huwenfeng_2011/article/details/43416523 下面是下部分 C2S 1.当有客户端进行连接时根据Mina框架的模式首先调 ...
- git分布式版本控制系统权威指南学习笔记(一):配置文件、简单流程和小问题
文章目录 git配置文件简介 git config各种命令 配置级别: 用户信息 文本编辑器 差异分析工具 配置命令别名 公钥 git协同流程 简单流程 初始化版本库 提交至缓存区 查看状态 提交分支 ...
- 无法将 Ethernet0 连接到虚拟网络”VMnet0″ 详细信息可以在 vmware.log 文件中找到未能连接虚拟机Ethernet0
在 vmware“编辑->虚拟网络设置”里面,点“恢复默认”可解决.
- package com.nps.base.xue.xd.groovyEngine import com.google.gson.Gson import com.google.gson.reflect.TypeToken import com.nps.common.service.NpsApplicationContextHolder import com.nps.data_api.service
原因: Switch this to "false" to let the transaction originator make the rollback decision. I ...