




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、閱讀程序?qū)懡Y(jié)果專題三分析閱讀程序?qū)懡Y(jié)果專題三分析練習(xí)1 var i, s, max: integer; a :array 1.10 of integer; begin for i:=1 to 10 do read (ai); max:=a1 ;s:=a1; for i:=2 to 10 do begin if smax then max:=s end; writeln(max=, MAX) end. 輸入:8 9 -1 24 6 5 11 15 -28 9輸出:max=77輸入:2 3 -6 -1 1 2 3 -9 4 6輸出:max= 10本質(zhì)是求一個(gè)本質(zhì)是求一個(gè)n長的整數(shù)數(shù)列的連續(xù)子序列的
2、和最大!長的整數(shù)數(shù)列的連續(xù)子序列的和最大!練習(xí)2const n=10;var s,i : integer;function co(i1:integer) : integer; var j1,s1 : integer; begin s1:=n; for j1:= (n-1) downto (n-i1+1) do s1:= s1*j1 div (n-j1+1); co:=s1 end;begin s:=n+1; for i:= 2 to n do s:=s + co(i); writeln(s=,s);end.輸出:_1024co(2)s1:=10*9/2co(3)s1:=10*9/2 *8/3c
3、o(4)s1:=10*9/2 *8/3 *7/4S1=45S1=120S1=210co(5)S1:=10*9*8*7*62*3*4*5S1=252co(6)S1:=10*9*8*7*6*52*3*4*5*6S1=210co(7)S1:=10*9*8*7*6*5*42*3*4*5*6*7S1=120co(8)S1:=10*9*8*7*6*5*4*32*3*4*5*6*7*8S1=45co(9)S1:=10*9*8*7*6*5*4*3*22*3*4*5*6*7*8*9S1=10co(10) S1:=10*9*8*7*6*5*4*3*2*12*3*4*5*6*7*8*9*10S1=1組合數(shù)定義 :從
4、n個(gè)不同元素中取出r(rn)個(gè)元素的所有組合的個(gè)數(shù)。例:從A、B、C、D、E五個(gè)球中任取2個(gè)有多少種方案?5!2!*(5-2)!=10練習(xí)3var i,j,s:integer; b :array0.5 of integer; begin s:=1; for i:=1 to 5 do bi:=i; j:=1; while j0 do begin j:=5; while (j0) and (bj=10+j-5) do j:=j-1; if j0 then begin s:=s+1; bj:=bj+1; for i:=j+1 to 5 do bi:=bj+i-j end; end; writeln(
5、s=,s); end.輸出:_2521098766 7 8 91056 7 8 910 for i:=0 to k do ai:=i;while a0 do begin j:=k; while aj=n-(k-j) do j:=j-1; aj:=aj+1; for i:=j+1 to k do ai:=ai-1+1; end;最大值最大值 4-(3-j) 1 2 3 4 jjj321340 1jjj2jjj第二種枚舉第二種枚舉(利用利用while循環(huán)產(chǎn)生排列串循環(huán)產(chǎn)生排列串)例例6選數(shù)(選數(shù)(NOIP2002初中組復(fù)賽第二題)初中組復(fù)賽第二題)問題描述:問題描述:已知n(1=n=20)個(gè)整數(shù)x
6、1,x2,xn(1=xi=5000000),以及一個(gè)整數(shù)k(kn)。從n個(gè)整數(shù)中任選k個(gè)整數(shù)相加,可分別得到一系列的和。例如當(dāng)n=4,k=3,4個(gè)整數(shù)分別為3,7,12,19時(shí),可得到的全部組合及它們的和為3+7+12=22,3+7+19=29,7+12+19=38,3+12+19=34?,F(xiàn)在,要求你計(jì)算出和為素?cái)?shù)的組合共有多少種。如上例中,只有一種組合的和為素?cái)?shù):3+7+19=29。輸入: n , k x1,x2,xn輸出:一個(gè)整數(shù)(滿足條件的組合個(gè)數(shù))樣例樣例輸入:4 33 7 12 19輸出:1分析:分析:本題可分解成以下兩部分:從n個(gè)數(shù)中任取k個(gè)數(shù)的組合因?yàn)閚0 do begin j:
7、=5; while (j0) and (bj=10+j-5) do j:=j-1; if j0 then begin s:=s+1; bj:=bj+1; for i:=j+1 to 5 do bi:=bj+i-j end; end; writeln(s=,s); end.輸出:_2521098766 7 8 91056 7 8 910從10個(gè)不同的球中任取5個(gè)有多少種方案?10!5!*(10-5)!=252練習(xí)4vari,j,n:longint; procedure m(s:longint); var i:longint; begin for i:=1 to s div 2 do m(i);
8、j:=j+1; end;beginreadln(n); m(n); writeln(j);end.輸入:8輸出:_m(8)1234m(1)j=1m(2)m(1)j=2j=3m(3)m(1)j=4j=5m(4)m(1)m(1)j=6m(2)m(1)j=7j=8j=9j=10練習(xí)5 const n=4;type se=array1.n*2 of char;var i,j,i1,j1,k,s,t,s1,l,swap:integer; temp:char; a:se;begin for i:=1 to n*2 do read(ai); readln; s:=0; t:=0; for i:=1 to n
9、*2 do if ai=1 then s:=s+1 else if ai=0 then t:=t+1; if (sn) or (tn) then writeln(error) else begin end;end.輸入:10101100 輸出:_ s1:=0; for i:=1 to 2*n-1 do if aiai+1 then s1:=s1+1; writeln(jamp=,s1); swap:=0; for i:=1 to 2*n-1 do for j:=i+1 to 2*n do if aiaj then begin temp:=ai;ai:=aj ;aj:=temp; s:=0; f
10、or l:=1 to 2*n-1 do if alal+1 then s:=s+1; if sswap then begin swap:=s; i1:=i; j1:=j; end; temp:=ai; ai:=aj; aj:=temp end; if swap0 then writeln(maxswap=,swap-s1, i=,i1, j=,j1)輸入:10101100jamp=510101010maxswap=2 i=6 j=7練習(xí)6 vara,t:string; i,j:integer; begina:=morning;j:= 1; for i:=2 to 7 do if (ajaj+1
11、then begin aj:=aj+aj+1; aj+1:=aj-aj+1; aj:=aj-aj+1; end; end; j:=1; while (aj=0)and (j100)do j:=j+1; for i:=j to 100 do a0=a0+ai; writeln(a0); end. 本題的運(yùn)行結(jié)果是: 970 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
12、50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99100練習(xí)8var i,j,k,n,l0,l1,lk:integer;a :array 0.20 of integer;beginreadln(n,k);for i:=0 to n-1 do ai:=i+1;an:=an-1; l0:=n-1; lk:=n-1;for i:=1 to n-1 dobegin l1:=l0-k; if (l10)do beginj:=j-1; aj:=n mod 10; n:=n div 10;end;s:=0;for i:=j t0 20 do s:=s*p+ai;writeln(s); j :=21;while (s0)dobegin j:=j-1; aj:=s mod q; s:=s div q;end;for i:=j to 20 do write(ai);readln;end.輸入:7 3051 8 輸出
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 土地抵押借款合同(2025年度)生態(tài)農(nóng)業(yè)貸款
- 2025年中國塑料包裝透明盒市場調(diào)查研究報(bào)告
- 2025年中國U型上下無框玻璃門專用電插鎖市場調(diào)查研究報(bào)告
- 2025至2031年中國麻椒粉行業(yè)投資前景及策略咨詢研究報(bào)告
- 2025至2031年中國裝飾玻璃球行業(yè)投資前景及策略咨詢研究報(bào)告
- 2025至2031年中國網(wǎng)絡(luò)防病毒軟件行業(yè)投資前景及策略咨詢研究報(bào)告
- 防水轉(zhuǎn)包工合同范本
- 銀行股權(quán)解壓合同范本
- 林木整體出售合同范本
- 2025年伊犁職業(yè)技術(shù)學(xué)院單招職業(yè)技能測試題庫及參考答案
- 水利水電工程單元工程施工質(zhì)量驗(yàn)收評定表及填表說明
- 2024年廣東中考道德與法治試卷答案講解及備考指導(dǎo)(深度課件)
- HG+20231-2014化學(xué)工業(yè)建設(shè)項(xiàng)目試車規(guī)范
- HG-T 2006-2022 熱固性和熱塑性粉末涂料
- 公用水泵房和雨水泵房設(shè)備調(diào)試方案
- 2024年江蘇農(nóng)牧科技職業(yè)學(xué)院單招職業(yè)適應(yīng)性測試題庫附答案
- Access數(shù)據(jù)庫應(yīng)用技術(shù) 教案 全套 項(xiàng)目:1-8
- 庭院工程暫預(yù)算報(bào)價(jià)單(龍威景觀)
- 教學(xué)評一體化
- 2023年全國高考體育單招考試英語試卷試題真題(精校打印版)
- 2023年四川省綿陽市中考化學(xué)試卷真題(含答案與解析)
評論
0/150
提交評論