jzoj3362,bzoj3758-[NOI2013模拟]数数【分段打表,背包,状压】

正题

bzojbzojbzoj链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3758


题目大意

A∼BA\sim BAB中有多少个数满足数字上的位数可以分成两个和相等的集合。


解题思路

首先我们考虑如何快速判断一个数是否是满足要求的数,我们可以用背包,设fif_ifi表示iii是否可行,若fsum2f_{\frac{sum}{2}}f2sum可行,就可行,那么有fi=fiorfi−numif_i=f_i\ or\ f_{i-num_i}fi=fi or finumi。时间复杂度:O(n∗sum2):O(n*\frac{sum}{2}):O(n2sum)其中sumsumsum最大为818181,显然不能胜任本题。

我们考虑优化fff,设FFF的第iii位表示原来的fif_ifi,那么我们将FFF左移iii位就表示F+iF+iF+i的可行方案,也就有了F=ForF∗2numiF=F\ or\ F*2^{num_i}F=F or F2numi。时间复杂度O(nlog10num)O(n\ log_{10}\ num)O(n log10 num)

但是依旧不能胜任本题,我们考虑分段打表,数据最大为10910^9109那么让初始数组aia_iai表示i∗106i*10^6i106时有多少个满足条件的数字
那么每次处理让前面一整块的直接赋值,后面多余的暴力,时间复杂度:O(N%106):O(N\% 10^6):O(N%106)

打表程序最后有


ACcodeACcodeACcode

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int b[1100]={1,
376414,832548,1288829,1744957,2196801,
2647717,3090921,3526441,3951373,4366881,
4823016,5304767,5797145,6290673,6782005,
7272531,7758911,8238397,8710537,9182259,
9638540,10130919,10610576,11103530,11590746,
12080514,12565095,13045217,13523104,13996048,
14452176,14945704,15438659,15913606,16403908,
16892728,17371944,17858308,18339126,18810720,
19262564,19753896,20241112,20731415,21199400,
21684698,22170474,22655526,23128983,23601311,
24052227,24542753,25032521,25521341,26006640,
26480513,26967739,27450345,27929455,28401297,
28844501,29330881,29815462,30294678,30780454,
31267681,31727884,32207446,32681532,33151142,
33586662,34066148,34546270,35032634,35517686,
36000292,36479855,36928876,37398606,37865238,
38290170,38762310,39240197,39721015,40194472,
40673582,41147668,41617399,42050820,42514128,
42929636,43401358,43874302,44345896,44818224,
45290066,45759676,46226308,46689617,47111408,
47567543,48049294,48541672,49035200,49526532,
50017058,50503438,50982924,51455064,51926787,
52408538,52900917,53398018,53897102,54395977,
54894265,55390377,55882155,56370125,56858337,
57350716,57847817,58346902,58846683,59346651,
59846495,60345547,60842737,61337763,61832644,
62326172,62825257,63325038,63822619,64321882,
64821478,65319368,65818160,66315615,66811193,
67302525,67801400,68301369,68800632,69295187,
69792676,70292150,70790950,71286704,71781714,
72272240,72770528,73270372,73769969,74267458,
74763403,75261352,75759528,76256606,76751556,
77237936,77734048,78233100,78730990,79230465,
79728414,80220835,80714564,81209374,81704150,
82183636,82675414,83172604,83671396,84170196,
84668373,85162102,85646751,86134012,86626602,
87098742,87586712,88081738,88579193,89074947,
89572025,90066836,90554097,91029272,91513943,
91985665,92473877,92968758,93464336,93959346,
94454296,94949072,95441663,95926334,96400456,
96856737,97349116,97828773,98321727,98808943,
99298711,99783292,100263414,100741301,101214245,
101706624,102203725,102702810,103202591,103702559,
104202403,104701455,105198645,105693671,106188553,
106668210,107167294,107654510,108153409,108643572,
109140448,109631937,110124935,110615087,111104171,
111597126,112096907,112595805,113093028,113592811,
114091416,114589182,115087419,115585177,116080739,
116567955,117067924,117558087,118057869,118549358,
119048443,119540444,120037758,120529914,121025142,
121514910,122014754,122511631,123010236,123509320,
124005152,124504321,124999108,125496724,125991519,
126476100,126975152,127466641,127964408,128456409,
128955577,129444362,129941989,130432182,130927550,
131407672,131904862,132397860,132896097,133393412,
133888199,134385825,134870791,135365762,135853349,
136331236,136826262,137316414,137814172,138306328,
138803945,139294138,139789108,140268614,140761870,
141234814,141729695,142218779,142714341,143209569,
143704364,144199733,144687320,145180576,145654893,
146111021,146604549,147097504,147572451,148062753,
148551573,149030789,149517153,149997971,150469565,
150963093,151462178,151961959,152459540,152958803,
153458399,153956289,154455081,154952536,155448114,
155941069,156440850,156939748,157436971,157936754,
158435359,158933125,159431362,159929120,160424683,
160899630,161397210,161894433,162373649,162870480,
163366197,163847036,164342308,164834857,165316243,
165806546,166305809,166805591,167302422,167797534,
168296440,168794207,169291182,169787228,170282584,
170771404,171271001,171769606,172265322,172764228,
173259686,173756940,174255103,174749456,175244788,
175724004,176221894,176719661,177200500,177698266,
178195520,178676906,179174054,179669963,180151504,
180637868,181136660,181634897,182130170,182627145,
183125307,183622455,184112943,184610047,185104839,
185585657,186083112,186580870,187073419,187569466,
188063819,188559727,189056831,189540681,190034892,
190506486,191002064,191497626,191979012,192474368,
192969701,193451242,193946034,194440245,194913069,
195364913,195856245,196343461,196833764,197301749,
197787047,198272823,198757875,199231332,199703660,
200194992,200693867,201193836,201693099,202187654,
202685143,203184617,203683417,204179171,204674181,
205161397,205661366,206151529,206651311,207142800,
207641885,208133886,208631200,209123356,209618584,
210108887,210608150,211107932,211604763,212099875,
212598781,213096548,213593523,214089569,214584926,
215052911,215547465,216038954,216534066,217007523,
217499719,217990902,218484411,218959906,219446728,
219932027,220429516,220928600,221427506,221919702,
222413232,222911994,223409873,223904584,224393575,
224879351,225378826,225870827,226368593,226859776,
227358538,227847478,228346120,228838090,229333644,
229818696,230317496,230814811,231311786,231805294,
232303173,232801815,233291626,233787284,234281778,
234755235,235250989,235743145,236239192,236714687,
237209397,237701367,238197025,238673285,239165609,
239637937,240132947,240628175,241123531,241610354,
242099345,242594899,243089393,243581717,244056063,
244506979,244997505,245487273,245976093,246461392,
246935265,247422491,247905097,248384207,248856049,
249346575,249844863,250344707,250844304,251341793,
251837738,252335687,252833863,253330941,253825891,
254315659,254815503,255312380,255810985,256310069,
256805901,257305070,257799857,258297473,258792268,
259281088,259780685,260279290,260775006,261273912,
261769370,262266624,262764787,263259140,263754472,
264239771,264737260,265236344,265735250,266227446,
266720976,267219738,267717617,268212328,268701320,
269175193,269671137,270166969,270662427,271155957,
271637395,272132981,272626657,273118402,273606214,
274093441,274591390,275090558,275587812,276086574,
276582160,277074754,277572088,278069042,278564273,
279046879,279545056,280039843,280538005,281035884,
281529560,282026894,282513144,283009665,283502663,
283981773,284478851,284976468,285470821,285965531,
286457276,286954230,287450751,287934209,288427697,
288899539,289394489,289889284,290384617,290873608,
291361420,291856651,292349649,292843137,293317367,
293760571,294246951,294731532,295210748,295696524,
296183751,296643954,297123516,297597602,298067212,
298553592,299049704,299548756,300046646,300546121,
301044070,301536491,302030220,302525030,303019806,
303504387,304003439,304494928,304992695,305484696,
305983864,306472649,306970276,307460469,307955837,
308435053,308932943,309430710,309911549,310409315,
310906569,311387955,311885103,312381012,312862553,
313348329,313847804,314339805,314837571,315328754,
315827516,316316456,316815098,317307068,317802622,
318289849,318787798,319286966,319784220,320282982,
320778568,321271162,321768496,322265450,322760682,
323220885,323713305,324202090,324683476,325172416,
325665010,326128509,326618473,327104746,327585454,
328065017,328558746,329056372,329553520,330052162,
330549496,331039460,331524706,332017240,332510935,
332985021,333479832,333970025,334465933,334957903,
335454857,335941130,336433664,336912904,337405294,
337874904,338369680,338865049,339346590,339842144,
340337375,340818083,341311778,341804168,342276695,
342712215,343191701,343671823,344158187,344643239,
345125845,345605408,346054429,346524159,346990791,
347470277,347962055,348459245,348958037,349456837,
349955014,350448743,350933392,351420653,351913243,
352393365,352890555,353383553,353881790,354379105,
354873892,355371518,355856484,356351455,356839042,
357325406,357824198,358322435,358817708,359314683,
359812845,360309993,360800481,361297585,361792377,
362277429,362776229,363273544,363770519,364264027,
364761906,365260548,365750359,366246017,366740511,
367223117,367721294,368216081,368714243,369212122,
369705798,370203132,370689382,371185903,371678901,
372158464,372652193,373149819,373646967,374145609,
374642943,375132907,375618153,376110687,376604383,
377053404,377538052,378023018,378513506,379003317,
379489567,379974813,380427197,380908306,381388632,
381858363,382345624,382840594,383337698,383833356,
384329877,384822411,385303520,385778158,386266144,
386732776,387225367,387712954,388207746,388702240,
389195238,389688933,390169259,390657245,391130375,
391555307,392027447,392505334,392986152,393459609,
393938719,394412805,394882536,395315957,395779265,
396251405,396739375,397234401,397731856,398227610,
398724688,399219499,399706760,400181935,400666606,
401144493,401639519,402129671,402627429,403119585,
403617202,404107395,404602365,405081871,405575127,
406055945,406553400,407051158,407543707,408039754,
408534107,409030015,409527119,410010969,410505180,
410978637,411474391,411966547,412462594,412938089,
413432799,413924769,414420427,414896687,415389011,
415868121,416365199,416862816,417357169,417851879,
418343624,418840578,419337099,419820557,420314045,
420788131,421282942,421773135,422269043,422761013,
423257967,423744240,424236774,424716014,425208404,
425678135,426165396,426660366,427157470,427653128,
428149649,428642183,429123292,429597930,430085917,
430519338,430994512,431474018,431957868,432434128,
432917586,433396826,433871464,434306087,434779291,
435242600,435727271,436220527,436714738,437207062,
437700550,438192940,438680926,439154130,439626260,
440041768,440513490,440986434,441458028,441930356,
442402198,442871808,443338440,443801749,444223540,
444695262,445183474,445678355,446173933,446668943,
447163893,447658669,448151260,448635931,449110053,
449582997,450077878,450566962,451062524,451557752,
452052547,452547916,453035503,453528759,454003076,
454474670,454970248,455465810,455947196,456442552,
456937885,457419426,457914218,458408429,458881253,
459353581,459848591,460343819,460839175,461325998,
461814989,462310543,462805037,463297361,463771707,
464243549,464738499,465233294,465728627,466217618,
466705430,467200661,467693659,468187147,468661377,
469130987,469625763,470121132,470602673,471098227,
471593458,472074166,472567861,473060251,473532778,
473999410,474492001,474979588,475474380,475968874,
476461872,476955567,477435893,477923879,478397009,
478860318,479344989,479838245,480332456,480824780,
481318268,481810658,482298644,482771848,483243979,
483665770,484139892,484614209,485087033,485561379,
486035609,486508136,486981266,487453396,487875964};
const int T=1000000;
bool check(int x)
{int i=x,tot=0;long long f=1;while(i) tot+=i%10,i/=10;if(tot&1) return 0;tot>>=1;i=x;while(i) f|=(f<<i%10),i/=10;return (f>>tot)&1;
}
int solve(int x)
{int ans=b[x/T];for(int i=x/T*T+1;i<=x;i++)ans+=check(i);return ans;
}
int main()
{int A,B;scanf("%d%d",&A,&B);printf("%d",solve(B)-solve(A-1));
}

打表codecodecode

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<windows.h>
using namespace std;
int sum;
bool check(int x)
{int i=x,tot=0;long long f=1;while(i) tot+=i%10,i/=10;if(tot&1) return 0;tot>>=1;i=x;while(i) f|=(f<<i%10),i/=10;return (f>>tot)&1;
}
int main()
{freopen("biao.out","w",stdout);printf("{");for(int i=0;i<=1000000000;i++){sum+=check(i);if(i%1000000==0){printf("%d,",sum);cerr<<(double)i/1000000000*100*1.0<<'%'<<endl;}if(i%5000000==0) printf("\n");}printf("}");
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/322198.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Nacos(八)之Docker

转载自 Nacos Docker 快速开始 操作步骤 Clone 项目 git clone https://github.com/nacos-group/nacos-docker.git cd nacos-docker单机模式 Derby docker-compose -f example/standalone-derby.yaml up单机模式 MySQL 如果希望使用MySQL5.7 docker-compose -f example/sta…

微软高管解读财报:努力创新云基础架构

2月1日&#xff0c;微软发布了该公司截至2017年12月31日的2018年第二财季财报&#xff08;即2017年第四季度&#xff09;。财报显示&#xff0c;微软第二财季营收为289.18亿美元&#xff0c;比上年同期的258.26亿美元增长了12%。受税改与就业法案相关的一次性费用138亿美元的影…

欢乐纪中某A组赛【2019.7.12】

前言 暴力写挂垫底了呀\huge \color{red}\texttt{暴力写挂}\small\color{white}\\\texttt{垫底了呀}暴力写挂垫底了呀 %%%ZZYrank1\texttt{\%\%\% ZZY rank1}%%% ZZY rank1 成绩 JJJ表示初中&#xff0c;HHH表示高中后面加的是几年级 RankRankRankPersonPersonPersonScoreScore…

Nacos(九)之Dubbo 融合 Nacos 成为注册中心

转载自 Dubbo 融合 Nacos 成为注册中心 Nacos 作为 Dubbo 生态系统中重要的注册中心实现&#xff0c;本文将会介绍如何进行 Dubbo 对接 Nacos 注册中心的工作。 预备工作 请确保后台已经启动 Nacos 服务&#xff0c;可先行参考 Nacos 快速入门。 快速上手 Dubbo 融合 Nac…

在.NET Core中处理一个接口多个不同实现的依赖注入问题

前言近段时间在准备公司的技术分享&#xff0c;所以这段时间将大部分时间放在准备分享内容上去了。博客也就停了一下下。在.NET Core中处理依赖注入问题时&#xff0c;往往是定义好了一个操作规范的接口&#xff0c;会有N多个基于不同技术的实现&#xff0c;根据实际情况在项目…

P3085,jzoj3234-[USACO13OPEN]阴和阳【点分治】

正题 题目链接:https://www.luogu.org/problemnew/show/P3085 题目大意 一棵树只有−1-1−1和111的边权&#xff0c;询问有多少条路径可以找到一个分界点使得分出的两条路径长度为000。 解题思路 询问路径显然点分治一波。 然后考虑分界点的两种情况 分界点在当前扫描到的…

Nacos(十)之Kubernetes Nacos

转载自 Kubernetes Nacos 本项目包含一个可构建的Nacos Docker Image&#xff0c;旨在利用StatefulSets在Kubernetes上部署Nacos 快速开始 Clone 项目 git clone https://github.com/nacos-group/nacos-k8s.git简单例子如果你使用简单方式快速启动,请注意这是没有使用持久化…

.net core连接MongoDB

前两天在学习MongoDB相关的知识&#xff0c;做了个小Demo&#xff0c;做的是省份下面有多少所学校&#xff0c;嗯&#xff0c;做的比较粗暴。。。连接MongoDB首先要通过Nuget添加一个MongoDB的包&#xff0c;下载此包安装完毕后开始写代码了&#xff0c;创建一个省份实体&#…

P4139-上帝与集合的正确用法【欧拉定理】

正题 题目链接:https://www.luogu.org/problemnew/show/P4139 题目大意 求2222222...%p2^{2^{2^{2^{2^{2^{2^{...}}}}}}}\%p2222222...%p 解题思路 欧拉定理 ab{ab%φ(p)φ(p)(b>φ(p))ab%φ(p)(b≤φ(p))a^b\left\{\begin{matrix}a^{b\%\varphi(p)\varphi(p)}(b>\var…

Nacos(十一)之NacosSync 介绍

转载自 NacosSync 介绍 介绍 NacosSync是一个支持多种注册中心的同步组件,基于Spring boot开发框架,数据层采用Spring Data JPA,遵循了标准的JPA访问规范,支持多种数据源存储,默认使用Hibernate实现,更加方便的支持表的自动创建更新使用了高效的事件异步驱动模型, 支持多种自…

Ocelot 集成Butterfly 实现分布式跟踪

微服务&#xff0c;通常都是用复杂的、大规模分布式集群来实现的。微服务构建在不同的软件模块上&#xff0c;这些软件模块&#xff0c;有可能是由不同的团队开发、可能使用不同的编程语言来实现、有可能布在了几千台服务器&#xff0c;横跨多个不同的数据中心。因此&#xff0…

jzoj1213-棋盘上的士兵【状压dp】

正题 题目大意 一个骑士会攻击对角线的位置&#xff0c;然后n∗nn*nn∗n的棋盘上放mmm个骑士求方案数。 解题思路 我们将棋盘翻转以两个对角线为中间&#xff0c;这样骑士就变成了横着打和竖着打。 设fi,s,jf_{i,s,j}fi,s,j​表示第iii条对角线&#xff0c;不能放置骑士的位置…

Nacos(十二)之Java SDK

转载自 Java SDK 概述部分 Maven 坐标 <dependency> <groupId>com.alibaba.nacos</groupId> <artifactId>nacos-client</artifactId> <version>${version}</version> </dependency>配置管理 获取配置 描述 用于服务启动…

聊聊AspectCore动态代理中的拦截器(一)

前言在上一篇文章使用AspectCore动态代理中&#xff0c;简单说明了AspectCore.DynamicProxy的使用方式&#xff0c;由于介绍的比较浅显&#xff0c;也有不少同学留言询问拦截器的配置&#xff0c;那么在这篇文章中&#xff0c;我们来详细看一下AspectCore中的拦截器使用。两种配…

P5135-painting【组合数学】

正题 题目链接:https://www.luogu.org/problemnew/show/P5135 题目大意 n∗mn*mn∗m的矩阵每列恰好有一个黑格子&#xff0c;询问两个中一个 每列黑格子所在行数不下降每列黑格子所在行数单调上升 的方案数 解题思路 显然询问1答案就是Cnm−1mC_{nm-1}^mCnm−1m​(插板法) …

你可能不知道的.Net Core Configuration

执行原理1. 配置读取顺序&#xff1a;与代码先后顺序一致。public Startup(IHostingEnvironment env){var builder new ConfigurationBuilder().SetBasePath(env.ContentRootPath).AddJsonFile("appsettings.json", false, true).AddJsonFile("cussettings.jso…

Dubbo(一)之简介

转载自 Dubbo 2.7入门 一、背景 本文介绍了网站应用的演进 随着互联网的发展&#xff0c;网站应用的规模不断扩大&#xff0c;常规的垂直应用架构已无法应对&#xff0c;分布式服务架构以及流动计算架构势在必行&#xff0c;亟需一个治理系统确保架构有条不紊的演进。 单一…

P1600-天天爱跑步【LCA,桶,树上差分】

正题 题目链接:https://www.luogu.org/problemnew/show/P1600 题目大意 一棵nnn个点的树&#xff0c;通过每条边需要时间为1。有mmm个玩家从SiS_iSi​跑到TiT_iTi​&#xff08;不停留&#xff0c;跑完之后马上消失&#xff09;。然后对于第iii个点求第wiw_iwi​刻停留在改点…

Dubbo(二)之SpringBoot nacos集成

一、框架 使用springboot启动&#xff0c;注册中心现在naocs。 nacos安装 二、样例项目 &#xff08;1&#xff09;maven设置 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId> <…

ASP.NET Core Web API下事件驱动型架构的实现(三):基于RabbitMQ的事件总线

在上文中&#xff0c;我们讨论了事件处理器中对象生命周期的问题&#xff0c;在进入新的讨论之前&#xff0c;首先让我们总结一下&#xff0c;我们已经实现了哪些内容。下面的类图描述了我们已经实现的组件及其之间的关系&#xff0c;貌似系统已经变得越来越复杂了。其中绿色的…