




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
一、排序算法a:array[1..maxn]of 1——Select_sortprocedureselect_sort;fori:=1ton-1dofor一、排序算法a:array[1..maxn]of 1——Select_sortprocedureselect_sort;fori:=1ton-1doforj:=i+1tondoifa>a[j] procedureinsert_sort;fori:=2tondowhile(key<a[j])and(j>0)dobegina[j+1]:=a[j];dec(j);end;procedurebubble_sort;fori:=1ton-1forj:=ndowntoi+1doifa[j]<a[j-1]then procedureqsort(s,t:long i:=s;j:=t;x:=a[(i+j)divwhilenc(i);找左邊比他大的whilea[j]>xdodec(j);{找右邊比他小的}ifi<=jthen{交換}untilifs<juntilifs<jthenqsort(s,j);ifi<tthenqsort(i,t);procedureheap(i,n:long);{i個(gè)元素向下篩} whilej<=ndoif(j<n)and(a[j]<a[j+1])theninc(j);ifx<a[j]thenelsej:=n+1;procedureheap_sort;fori:=ndiv2downto1doheap(i,n);fori:=ndownto2doproceduremergesort(s,t:long ift-s=0thenexit;m:=(s+t)div2;fori:=1tom-s+1dob:=a[s+i-1];forj:=m+1totdoc[j-m]:=a[j];fork:=stotdoifthenbegina[k]:=b;inc(i);endelsebegina[k]:=c[j];inc(j);end;7——基數(shù)排序、計(jì)數(shù)排序、桶排序二、高精度算法——High_precibignum=array[0..maxlen]of ;0functioncompare(a,b:bignum):long thenbegina[k]:=b;inc(i);endelsebegina[k]:=c[j];inc(j);end;7——基數(shù)排序、計(jì)數(shù)排序、桶排序二、高精度算法——High_precibignum=array[0..maxlen]of ;0functioncompare(a,b:bignum):long whilea[a[0]]=0dodec(a[0]);{檢查位數(shù)是否正確[b[0]]=0dowhileifa[0]>b[0]thenifa[0]<b[0]thenexit(-1);fori:=a[0]downto1doifa>bthenexit(1);ifa<bthenexit(-1);2procedureadd(a,b:bignum;varc:bignum); ifa[0]>b[0]thenelsefori:=1tofori:=1tofori:=1toc[0]doinc(c[i+1],cdivmaxcount);c:=cmod10;whilec[c[0]+1]>0doinc(c[c[0]+1],c[c[0]]divc[c[0]]:=c[c[0]]inc(c[c[0]+1],c[c[0]]divc[c[0]]:=c[c[0]]modmaxcount;procedureminus(a,b:bignum;varc:bignum); fori:=1toc[0]doc:=a-b;fori:=1toc[0]doifc<0thenwhile(c[0]>1)and(c[c[0]]=0)dodec(c[0]);proceduremulnum(a:bignum;x:long ,varc:bignum); fori:=1toc[0]doc:=a*x;fori:=1toc[0]doinc(c[i+1],cdivmaxcount);c:=cmod10;whilec[c[0]+1]>0doinc(c[c[0]+1],c[c[0]]divc[c[0]]:=c[c[0]]modmaxcount;proceduremul(a,b:bignum;varc:bignum); fori:=1toa[0]doforj:=1tob[0]dofori:=1toc[0]doinc(c[i+1],cdivmaxcount);c:=cmod10;fori:=1toa[0]doforj:=1tob[0]dofori:=1toc[0]doinc(c[i+1],cdivmaxcount);c:=cmod10;whilec[c[0]+1]>0doinc(c[c[0]+1],c[c[0]]divc[c[0]]:=c[c[0]]modmaxcount;6functiondivnum(a:bignum;x:long fori:=a[0]downto1doc:=tempdivx;temp:=tempmodx;whilec[c[0]]=0dodec(c[0]);7;var;procedurediv(a,b:bignum;varc,d:bignum); fori:=c[0]downto1dountilcompare(a,temp)>=0;whilec[c[0]]=0dodec(c[0]);810進(jìn)制數(shù)用bignumuntilcompare(a,temp)>=0;whilec[c[0]]=0dodec(c[0]);810進(jìn)制數(shù)用bignum記,maxcount=10kstring記repchar:array[0..35]ofstring=(‘0’,‘1’,’2’,……,’a’,’b’,……,’z’);——數(shù)碼對(duì)應(yīng)的字符repnum:array[48..122]oflong =(0,1,2……,34,35);——字符的ASCCI碼對(duì)應(yīng)的數(shù)碼k進(jìn)制轉(zhuǎn)十進(jìn)制:procedurechange_to_ten(s:string;k:long fori:=1tol-1dokprocedurechange_to_k(num:bignum;k:long whilenot((num[0]=1)and(num[1]=0))do遞歸 (歐幾里德算法 ifb=0then(b,amod非遞歸 ;<>0t:=a;a:=b;b:=tmodb;ifb=0then(b,amod非遞歸 ;<>0t:=a;a:=b;b:=tmodb;2functionextended_euclid(a,b:long ifb=0then;var;p:=extended_euclid(b,amodb,x,y);q:=x;x:=y;y:=q-adivb*y;3k:=a*b4 num:array[1..maxnnum]oflong proceduremodular_linear_equation(a,b,n:long ifbmodd<>0thenelse;varans.ansnum:=d;temp:=(x*(bdivd))modfori:=1toddoans.num:=(temp+i*(nans.ansnum:=d;temp:=(x*(bdivd))modfori:=1toddoans.num:=(temp+i*(ndivd))modn;5functionprime_bool(x:long fori:=2totrunc(sqrt(x))doifxmodi=0thenexit(false);6prime:array[0..maxprime]of;procedureprime_make; whilei<=maxnnumdoifnotpthenwhilei<=maxnnumdo;—1.排列生成算法——mna:array[0..maxn]of 遞歸proceduremake_permu ift=n+1)write(a[1]);fori:=2ton遞歸proceduremake_permu ift=n+1)write(a[1]);fori:=2tondowrite(‘‘,a);wrifori:=1tomdoifnotbthen非遞歸proceduremake_permu while(j<=m)and(b[j])ifj<=mthenbeginifi=nthen write(a[1]);forj:=2tondowrite(‘‘,a[j]);wrielsebeginelsebeginuntil2——mn ift=n+1 write(a[1]);fori:=2tondowrite(‘‘,a);wrifor2——mn ift=n+1 write(a[1]);fori:=2tondowrite(‘‘,a);wrifori:=a[t]tomdoifnotbthen3er:array[1..maxn]of eri i[1..maxn]oflong n的全排的字典序:functionget_number(n:long b:array[1..maxn]oflong fori:=1tondob:=i-1;fori:=1ton-1 ;forj:=a+1tondodec(b[j]);mnfunctionget_permu a:array[0..maxn]of ; fori:=1ton-1doa:=mmodm:=m fori:=1ton-1doa:=mmodm:=mdivfori:=1tondofork:=1toa[n-i]+1dowhile4——nmproceduremake_next(n,m:long fort:=1tomdowhile(i>1)and(a<a[i-1])dodec(i);whilea[j]<a[i-1]do fork:=ito(i+n)div2do1以點(diǎn)為基礎(chǔ)讀入(沒有特殊說明,一般以此方法讀入vetex:array[1..maxn,0..maxn]of ;——map:array[1..maxn,1..maxn]oflong procedureinitgraph; fori:=1toedomap:array[1..maxn,1..maxn]oflong procedureinitgraph; fori:=1toedo ;——u為起點(diǎn),v為終點(diǎn),wvetex:array[1..maxe]ofnode;——procedureinitgraph; fori:=1toewithvetexdoreadln(u,v,w);2——DFS 邊procedureDFS(t:long fori:=1tovetex[t,0]doifnotflag[vetex[t,i]]then3.廣度優(yōu)先搜索——BFSprocedureBFS(t:long x0:array[1..maxn]oflong;;;fori:=1tovetex[v,0]doifnot3.廣度優(yōu)先搜索——BFSprocedureBFS(t:long x0:array[1..maxn]oflong;;;fori:=1tovetex[v,0]doifnotflag[vetex[v,i]]thenuntilopen>=closed;4connected:array[1..maxn,0..maxn]oflong procedurestrongly_connected; ;sign:array[1..maxn]oflong proceduresort1(t:long fori:=1tondoif(map[t,i]<>0)and(notflag)thenprocedure fori:=1 fori:=1tondoif(notflag)and(map[i,t]<>0)thenfori:=1tondoifnotflagthenfori:=ndownto1doifnotflag[sign]then5proceduretopological_sort; fori:=1tondoifinv=0thenifclosed=0thenexit{error};fori:=1tovetex[v,0]doifnotflag[vetex[v,i]]thenifinv[vetex[v,i]]=0then;untilifclosed<nthenexit{error};6procedureprime_normal;untilifclosed<nthenexit{error};6procedureprime_normal; ;lowcost:array[1..maxn]oflong fori:=1tov[1,0]dofori:=2tondo forj:=1tondoif(notflag[j])and(lowcost[j]<min)thenforj:=1tov[mj,0]doif(notflag[v[mj,j]])and(lowcost[v[mj,j]]>map[mj,v[mj,j]])thenprocedurekruskal; functionfind(x:long ither[x]=xthenelsebeginqsort(1,e);——vetexwfori:=1tondovetex_powhile(last_set_num>1)and(vetex_poer<=e)doset1:=find(vetex[vetex_poer].u);set2:=find(vetex[vetex_poer].v);ifset1<>set2then vetex_powhile(last_set_num>1)and(vetex_poer<=e)doset1:=find(vetex[vetex_poer].u);set2:=find(vetex[vetex_poer].v);ifset1<>set2then 7procedureDijkstra(s:long fori:=1tondoforj:=1tonif(notflag[j])and(shortest[j]<min)forj:=1tovetex[mi,0]doif(notflag[vetex[mi,j]]) ap[mi,vetex[mi,j]])procedureFloyd; fori:=1tondoforj:=1tovetex[i,0]dofork:=1tondofori:=1tondoforj:=1tondoiflen[i,k]+len[k,j]<len[i,j]thenforj:=1tovetex[i,0]dofork:=1tondofori:=1tondoforj:=1tondoiflen[i,k]+len[k,j]<len[i,j]thenprocedureBellman-ford(s:long ;fori:=1ton-1doifboolthenforj:=1toeifshortest[vetex[j].v]>shortest[vetex[j].u]+vetex[j].wthenforj:=1toeifshortest[vetex[j].v]>shortest[vetex[j].u]+vetex[j].wthenproced
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 二手車銷售質(zhì)量保證合同書
- 政府項(xiàng)目招標(biāo)與投標(biāo)操作手冊(cè)
- 分季度財(cái)務(wù)預(yù)算明細(xì)表
- 農(nóng)村農(nóng)業(yè)項(xiàng)目資金使用協(xié)議
- 基礎(chǔ)工作流程簡(jiǎn)明教程與指南
- 員工辦公電腦使用說明書
- 理發(fā)師學(xué)徒專用合同
- 《數(shù)學(xué)函數(shù)圖像理解與問題解決》
- 企業(yè)戰(zhàn)略聯(lián)盟合作能力提升效果評(píng)估預(yù)案
- 汽車股份轉(zhuǎn)讓合同
- 《預(yù)應(yīng)力混凝土管樁基礎(chǔ)技術(shù)規(guī)程》DB42@489-2008
- 社區(qū)老人智能手機(jī)使用培訓(xùn)課件
- 2024年7月13日云南省昆明市直遴選筆試真題及解析綜合管理崗
- 個(gè)人信息安全保護(hù)管理規(guī)定
- 化工行業(yè)員工職業(yè)發(fā)展規(guī)劃
- DL∕T 1881-2018 智能變電站智能控制柜技術(shù)規(guī)范
- 2023北京順義區(qū)招錄鄉(xiāng)村振興協(xié)理員及考察筆試歷年典型考題及考點(diǎn)剖析附答案帶詳解
- 中國(guó)慢性冠脈綜合征患者診斷及管理指南2024版解讀
- 超全讀書筆記-2萬(wàn)字
- 思政課課題國(guó)內(nèi)外研究現(xiàn)狀
- 醫(yī)院保安服務(wù)投標(biāo)技術(shù)方案(技術(shù)標(biāo))
評(píng)論
0/150
提交評(píng)論