题意:如果一个数字用十进制表示,有大于等于1个1,或者大于等于2个2,或者大于等于3个3,或者大于等于4个4,或者大于等于5个5,或者大于等于6个6,或者大于等于7个7,或者大于等于8个8,或者大于等于9个9 则称这个数字为好数字,问 $ l,r $ 区间内有多少个好数字。

数据范围 $ l,r <=10^9 $

对于这一题,我们可以分段打表,这题在 $ 1e6 $ 的范围内是可以无压力跑过的,于是我们将 $ 1e9 $ 分成 $ 1e3 $ 个 $ 1e6 $ 打表出整数部分,再去跑小的部分,然后就可以求解。

并且题目要求求好数字,我们可以转换为求出不是好数字的数字,然后拿 $ n $ 减去即可。(据说直接暴力枚举 $ + O_2 $ 是能 $ AC $ 的。

正解是数位 $ dp $ ,从左到右逐位确定当前位置的数字的值,并记录每个数字出现次数,当符合条件 (后⾯⽆论接什么数字,都⼩于 R) 的时候,剩下位数使⽤多重集的排列(组合数)计算。

打表程序

#include<bits/stdc++.h>
using namespace std;
long long a[20];
long long l,r;
long long ans;
bool cheak(int n){
int num[10];
for(int i=0;i<=9;++i) num[i]=0;
while(n){
int x=n%10;
num[x]++;
if(x&&num[x]>=x) return true;
n/=10;
}
return false;
}
int main(){
freopen("txt.out","w",stdout);
for(int i=1;i<=1e9;++i){
if(cheak(i)) ans++;
if(i>=1000000&&(!(i%1000000))) printf("%lld,",ans);
}
return 0;
}

$ AC $ 代码

#include<bits/stdc++.h>
using namespace std;
long long a[2000]={0,553087,1553086,2299402,2909068,3471934,4025965,4579099,5132186,5685272,6238359,7238359,8238359,9238359,10238359,11238359,12238359,13238359,14238359,15238359,16238358,16984675,17984675,18984674,19766990,20520146,21267197,22013555,22759872,23506188,24252504,24862171,25862170,26644486,27426802,28045828,28656424,29266138,29875805,30485471,31095137,31658004,32658003,33411159,34030185,34649211,35213022,35775936,36338803,36901669,37464535,38018567,39018566,39765617,40376213,40940024,41503835,42057914,42611946,43165977,43720008,44273143,45273142,46019500,46629214,47192128,47746207,48300286,48853421,49406555,49959689,50512777,51512776,52259093,52868760,53431627,53985659,54538794,55091929,55645016,56198103,56751190,57751189,58497505,59107171,59670037,60224068,60777202,61330289,61883376,62436462,62989549,63989548,64735864,65345530,65908396,66462427,67015561,67568648,68121734,68674821,69674821,70674821,71674821,72674821,73674821,74674821,75674821,76674821,77674821,78674821,79674821,80674821,81674821,82674821,83674821,84674821,85674821,86674821,87674821,88674821,89674821,90674821,91674821,92674821,93674821,94674821,95674821,96674821,97674821,98674821,99674821,100674821,101674821,102674821,103674821,104674821,105674821,106674821,107674821,108674821,109674821,110674821,111674821,112674821,113674821,114674821,115674821,116674821,117674821,118674821,119674821,120674821,121674821,122674821,123674821,124674821,125674821,126674821,127674821,128674821,129674821,130674821,131674821,132674821,133674821,134674821,135674821,136674821,137674821,138674821,139674821,140674821,141674821,142674821,143674821,144674821,145674821,146674821,147674821,148674821,149674821,150674821,151674821,152674821,153674821,154674821,155674821,156674821,157674821,158674821,159674821,160674821,161674821,162674821,163674821,164674821,165674821,166674821,167674821,168674820,169421137,170421137,171421136,172203452,172956608,173703659,174450017,175196334,175942650,176688967,177688967,178688967,179688967,180688967,181688967,182688967,183688967,184688967,185688967,186688967,187688967,188688967,189688967,190688967,191688967,192688967,193688967,194688967,195688967,196688966,197471283,198471283,199471282,200354248,201143044,201926080,202708438,203490755,204273071,205055387,205808544,206808544,207808543,208597339,209386135,210140026,210893224,211646381,212399537,213152693,213899745,214899745,215899744,216682780,217436671,218190562,218937655,219684707,220431758,221178809,221925168,222925168,223925167,224707525,225460723,226207816,226954909,227701268,228447626,229193984,229940302,230940302,231940301,232722618,233475775,234222827,234969186,235715545,236461862,237208179,237954496,238954496,239954495,240736811,241489967,242237018,242983376,243729693,244476010,245222326,245968643,246968643,247968642,248750958,249504114,250251165,250997523,251743840,252490156,253236472,253846139,254846138,255628454,256410770,257029796,257640392,258250106,258859773,259469439,260079106,261079106,262079106,263079106,264079106,265079106,266079106,267079106,268079106,269079106,270079105,270861422,271861422,272861421,273744387,274533183,275316219,276098577,276880894,277663210,278445526,279227843,280227842,281110809,282110808,282899604,283682640,284464998,285247315,286029631,286811947,287430974,288430973,289219769,290008565,290679431,291299387,291918461,292537488,293156514,293775540,294386137,295386136,296169172,296952208,297572164,298192120,298802764,299413361,300023957,300634553,301244268,302244267,303026625,303808983,304428057,305038701,305649345,306259060,306868774,307478488,308088156,309088155,309870472,310652789,311271816,311882413,312492128,313101843,313711510,314321177,314930844,315930843,316713159,317495475,318114501,318725097,319334811,319944478,320554145,321163811,321773478,322773477,323555793,324338109,324957135,325567731,326177445,326787112,327396778,328006444,328569311,329569310,330322466,330941492,331560518,332124329,332687243,333250110,333812976,334375843,335375843,336375843,337375843,338375843,339375843,340375843,341375843,342375843,343375843,344375842,345128999,346128999,347128998,347917794,348706590,349460481,350213679,350966836,351719992,352473148,353092175,354092174,354880970,355669766,356340632,356960588,357579662,358198689,358817715,359436741,360055768,361055767,361844563,362515429,363304225,363924181,364543255,365162282,365781308,366400334,366964146,367964145,368718036,369337992,369957948,370531519,371095378,371659190,372223001,372786812,373349727,374349726,375102924,375721998,376341072,376904931,377468790,378031705,378594619,379157533,379720401,380720400,381473557,382092584,382711611,383275423,383838338,384401253,384964120,385526987,386089854,387089853,387843009,388462035,389081061,389644872,390207786,390770653,391333520,391896386,392459253,393459252,394212408,394831434,395450460,396014271,396577185,397140052,397702918,398265784,398819816,399819815,400566866,401177462,401741273,402305084,402859163,403413195,403967226,404521258,405521258,406521258,407521258,408521258,409521258,410521258,411521258,412521258,413521258,414521257,415268309,416268309,417268308,418051344,418805235,419559126,420306219,421053271,421800322,422547373,423157970,424157969,424941005,425724041,426343997,426963953,427574597,428185194,428795790,429406386,429970198,430970197,431724088,432344044,432964000,433537571,434101430,434665242,435229053,435792864,436356676,437356675,438110566,438730522,439304093,439924049,440487908,441051720,441615531,442179342,442733422,443733421,444480514,445091158,445655017,446218876,446773900,447327980,447882059,448436138,448990171,449990170,450737222,451347819,451911631,452475443,453029523,453583603,454137635,454691667,455245699,456245698,456992749,457603345,458167156,458730967,459285046,459839078,460393110,460947141,461501173,462501172,463248223,463858819,464422630,464986441,465540520,466094552,466648583,467202614,467755749,468755748,469502106,470111820,470674734,471228813,471782892,472336027,472889161,473442296,474442296,475442296,476442296,477442296,478442296,479442296,480442296,481442296,482442296,483442295,484188654,485188654,486188653,486971011,487724209,488471302,489218395,489964754,490711112,491457470,492067185,493067184,493849542,494631900,495250974,495861618,496472262,497081977,497691691,498301405,498864320,499864319,500617517,501236591,501855665,502419524,502983383,503546298,504109212,504672126,505226206,506226205,506973298,507583942,508147801,508711660,509266684,509820764,510374843,510928922,511483002,512483001,513230094,513840738,514404597,514959621,515523480,516077560,516631639,517185718,517738854,518738853,519485212,520094927,520657842,521211922,521766002,522319185,522872320,523425455,523978590,524978589,525724947,526334661,526897575,527451654,528005733,528558868,529112003,529665137,530218272,531218271,531964629,532574343,533137257,533691336,534245415,534798550,535351684,535904818,536457906,537457905,538204222,538813889,539376756,539930788,540483923,541037058,541590145,542143233,543143233,544143233,545143233,546143233,547143233,548143233,549143233,550143233,551143233,552143232,552889550,553889550,554889549,555671866,556425023,557172075,557918434,558664793,559411110,560157427,560767095,561767094,562549411,563331728,563950755,564561352,565171067,565780782,566390449,567000116,567562984,568562983,569316140,569935167,570554194,571118006,571680921,572243836,572806703,573369570,573923603,574923602,575670654,576281251,576845063,577408875,577962955,578517035,579071067,579625099,580178235,581178234,581924593,582534308,583097223,583651303,584205383,584758566,585311701,585864836,586417972,587417971,588164330,588774045,589336960,589891040,590444223,590998303,591551438,592104573,592657661,593657660,594403977,595013644,595576511,596130543,596683678,597236813,597789901,598342988,598896076,599896075,600642392,601252059,601814926,602368958,602922093,603475228,604028315,604581402,605134489,606134488,606880804,607490470,608053336,608607367,609160501,609713588,610266675,610819762,611819762,612819762,613819762,614819762,615819762,616819762,617819762,618819762,619819762,620819761,621566078,622566078,623566077,624348393,625101549,625848600,626594958,627341275,628087592,628833908,629443575,630443574,631225890,632008206,632627232,633237828,633847542,634457209,635066876,635676542,636239409,637239408,637992564,638611590,639230616,639794427,640357341,640920208,641483075,642045941,642599973,643599972,644347023,644957619,645521430,646085241,646639320,647193352,647747384,648301415,648854550,649854549,650600907,651210621,651773535,652327614,652881693,653434828,653987963,654541097,655094185,656094184,656840501,657450168,658013035,658567067,659120202,659673337,660226425,660779512,661332600,662332599,663078916,663688583,664251450,664805482,665358617,665911705,666464840,667017927,667571014,668571013,669317329,669926995,670489861,671043892,671597026,672150113,672703200,673256286,673809373,674809372,675555688,676165354,676728220,677282251,677835385,678388472,678941558,679494645,680494645,681494645,682494645,683494645,684494645,685494645,686494645,687494645,688494645,689494644,690240961,691240961,692240960,693023276,693776432,694523483,695269841,696016158,696762474,697508790,698118457,699118456,699900772,700683088,701302114,701912710,702522424,703132091,703741757,704351423,704914290,705914289,706667445,707286471,707905497,708469308,709032222,709595089,710157955,710720821,711274853,712274852,713021903,713632499,714196310,714760121,715314200,715868232,716422263,716976294,717529429,718529428,719275786,719885500,720448414,721002493,721556572,722109707,722662841,723215975,723769063,724769062,725515379,726125046,726687913,727241945,727795080,728348215,728901302,729454389,730007476,731007475,731753791,732363457,732926323,733480354,734033488,734586575,735139662,735692748,736245835,737245834,737992150,738601816,739164682,739718713,740271847,740824934,741378020,741931108};
long long l,r;
long long size=1000000;
long long ans,tmp1,tmp2;
bool cheak(int n){
int num[10];
for(int i=0;i<=9;++i) num[i]=0;
while(n){
int x=n%10;
num[x]++;
if(x&&num[x]>=x) return true;
n/=10;
}
return false;
}
long long solve(int n){
long long ans=a[n/size];
for(int i=size*(n/size)+1;i<=n;++i){
if(cheak(i)) ans++;
}return ans;
}
int main(){
scanf("%lld %lld",&l,&r);
printf("%lld",solve(r)-solve(l-1));
return 0;
}

yzoj2424 小迟的数字 题解的更多相关文章

  1. yzoj 2372 小B的数字 题解

    题意 判断是否存在一个序列 $ b_i $ 使得 $ \prod_{i = 1}^{n} b_i  | b_i^{a_i}$ 恒成立,其中 $ b_i $ 中的每个数都是2的正整数次幂. 样例输入 3 ...

  2. 【BZOJ5074】[Lydsy十月月赛]小B的数字 数学

    [BZOJ5074][Lydsy十月月赛]小B的数字 题解:题目是问你ai*bi>=sum,bi>=0这个不等式组有没有解.因为a<=10,容易想到取ai的lcm,然后变成lcm*b ...

  3. 【BZOJ5071】[Lydsy十月月赛]小A的数字 发现性质

    [BZOJ5071][Lydsy十月月赛]小A的数字 题解:一般遇到这种奇奇怪怪的操作,常用的套路是将原序列差分一下,或者求个前缀和什么的.本题就是直接对原序列求前缀和,然后发现一次操作相当于交换两个 ...

  4. 小Z的袜子(题解)(莫队)

    小Z的袜子(题解)(莫队) Junlier良心莫队 题目 luoguP1494 [国家集训队]小Z的袜子 code #include<bits/stdc++.h> #define lst ...

  5. 小B的询问(题解)(莫队)

    小B的询问(题解)(莫队) Junlier良心莫队 题目 luoguP2709 小B的询问 code #include<bits/stdc++.h> #define lst long lo ...

  6. 题解 P4942 【小凯的数字】

    题目 为什么看到很多题解区的 dalao 都用逆元?是我太菜了吧 [分析] 首先,根据弃九验算法的原理,显然可以得到:一个 \(n\) 位数 \(a_1a_2a_3\dots a_n\equiv a_ ...

  7. [洛谷P4942][题解]小凯的数字

    这题打着高精的旗号其实是闹着玩的……(我不是题目) 数据范围就是提示你这题O(1)的 我们知道,一个数膜9的余数等于它数字和膜9的余数 我们可以把l到r加起来然后膜9 也就是(l+r)(r-l+1)/ ...

  8. [BZOJ 5071]小A的数字

    Description 小A成为了一个数学家,他有一串数字A1,A2...An 每次可以进行如下操作,选择一个数字i(1<i<=n),将(Ai-1,Ai,Ai+1) 变为(Ai-1 + A ...

  9. 小Z的袜子 题解报告【莫队】

    Description 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿.终于有一天,小Z再也无法忍受这恼人的找袜子过程,于是他决定听天由命-- 具体来说,小Z把这N只 ...

随机推荐

  1. Mixed Far-Field and Near-Field Source Localization Based on Subarray Cross-Cumulant

    基于子阵列互累积量(Cross-Cumulant)的远场和近场混合声源定位[1]. 文中采用Uniform linear array (ULA)阵列,将其分为两个互相重叠的子阵列,构建关于子阵列输出信 ...

  2. git log filter(六)

    显示前10条提交记录: root@vmuer-VirtualBox:/media/vmuer/share/cmake-uart-server# git log -10 commit b056dacb0 ...

  3. packr 方便的潜入静态资源文件到golang 二进制文件中

    类似的工具以前有介绍过statik,今天使用的工具是packr 也是很方便的golang tools 安装 go get -u github.com/gobuffalo/packr/packr 或者我 ...

  4. CSS块元素

    一.典型代表: Div h1-h6 p ul li 二.特点: 独占一行 可以设置宽高 嵌套(包含)下,子块元素宽度(没有定义情况下)和父块元素宽度默认一致. <style type=" ...

  5. 洛谷 P1522 牛的旅行 Cow Tours 题解

    P1522 牛的旅行 Cow Tours 题目描述 农民 John的农场里有很多牧区.有的路径连接一些特定的牧区.一片所有连通的牧区称为一个牧场.但是就目前而言,你能看到至少有两个牧区通过任何路径都不 ...

  6. ASP复古随机验证码

    <% Call Com_CreatValidCode("ValidCode") Sub Com_CreatValidCode(pSN) Response.Expires = ...

  7. Apache2 服务配置 ubuntu16.04 + django1.11

    (步骤) 环境 Ubuntu 16.04 Python 3.5.2 Django 1.11 Apache 2.4 1.Apache2安装 sudo apt-get install apache2 查看 ...

  8. kerberos 配置错误记录

    服务端错误记录: 1.服务端在创建数据库的时候报如下错误: # kdb5_util -s -r HADOOP.HOME 错误提示:kdb5_util: Improper format of Kerbe ...

  9. Cannot read property '_withTask' of undefined

    前言 Cannot read property '_withTask' of undefined 突然一下子,就报这个错了,刚刚还好好呢 Bug分析 1.是在template中调用了某个方法,但是你没 ...

  10. 【转】Android系统中Fastboot和Recovery所扮演的角色。

    Android 刷机过程中 Fastboot 和 Recovery 的作用是什么? 自己在知乎的一篇回答,,现在翻出来放到博客,希望可以解答更多人的疑惑,抑或有什么理解上的错误,也望网友指出~ 今天恰 ...