作業(yè)fence解題報(bào)告_第1頁(yè)
作業(yè)fence解題報(bào)告_第2頁(yè)
作業(yè)fence解題報(bào)告_第3頁(yè)
作業(yè)fence解題報(bào)告_第4頁(yè)
作業(yè)fence解題報(bào)告_第5頁(yè)
全文預(yù)覽已結(jié)束

付費(fèi)下載

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、FenceTime Limit:1000MSMemory Limit:30000KTotal Submit:177 Accepted:44DescriptionA team of k (1 = K = 100) workers should paa fence which contains N (1 = N= 16 000) pls numbered from 1 to N from left to right. Each worker i (1 = i =K) should sit in front of the plSi and he may paonly a compacterval (

2、this erval shoulds and for eachmeanst the pls from theerval should be consecutive). Thiscontahe Si pl. Also a worker should not pamoren Li plpaed plhe should receiv$ (1 = Pi = 10 000). A plshould be paedby no morenorker. All the numbers Si should be distinct.Being the teams leader you want to determ

3、ine for each worker theervalt he eshould pa, knowingt the totale should beal. The totalrepresents the sum of the workersale.Write a programt determines the totalale obtained by the K workers.InputThe inpontains:InputN KL1 P1 S1 L2 P2 S2.LK PK SKSemnificationN -the number of the pls; K ? the number o

4、f the workersLi -theal number of plst can be paed by worker iPi -the sum received by worker i for a paed plSi -the plin front of which sits the worker iOutputThe outpontains a singleeger, the totalale.SleInput83331422312357Sle Output17HExplanation of the sle:the worker 1 pas theerval 1, 2;the worker

5、 2 pas theerval 3, 4;the worker 3 pas theerval 5, 7;the worker 4 does not paany plSourceRomania OI 2002問(wèn)題簡(jiǎn)介(PKU1821):K 個(gè)工人受雇粉刷一段長(zhǎng)度為N 的。工人 I 粉刷的木板長(zhǎng)度過(guò) Li(可以為 0),他粉刷的木板必須是連續(xù)的,而且必須包含第 Si 號(hào)木板。第 I 個(gè)工人粉刷一塊木板可以得到 Pi 的?,F(xiàn)在要你計(jì)算機(jī)出 K 個(gè)工人最多可以得到多少。分析:這個(gè)題目明顯可以用動(dòng)態(tài)規(guī)劃解決。求解之前,將 K 個(gè)工人按其 Si 值從小到大排序。設(shè) FI,J表示前 I 個(gè)工人粉刷前 J 塊

6、木板可以得到的最大FI,J=Max FI,J - 1,F(xiàn)I1, J,F(xiàn)I- 1,K 1 + (J-K+1)*Pi。則說(shuō)明:K 是決策量,必須要滿足從第K 到第J 塊木板可以被第I 個(gè)工人一個(gè)人刷。這個(gè)算法的時(shí)間復(fù)雜度為O(K*N2),太慢了。感覺(jué)上這個(gè)題目和 NOI2006 第一試第三題有些類似,因此量K 滿足單調(diào)性。猜想最優(yōu)決策設(shè)求 FI,J時(shí),決策取 K1、K2(假定這兩個(gè)決策存在,并且 K1=L2,且 S1 比 S2 優(yōu)的充要條件是:(FI-1,K2-1 FI-1,K1-1)/ Pi (L1 L2)從上面的式子可以看到,L1、L2 是同時(shí)遞增的,而且 L1 會(huì)比 L2 先到達(dá) Li(到達(dá)

7、 Li 后就不能再遞增了),所以如果在求 FI,J時(shí),決策 K1 不比K2 優(yōu),那么,在求所有 FI,K時(shí)(KJ),決策 K1 也肯定不會(huì)比 K2 優(yōu)了。相反,如果求 FI,J時(shí),決策 K1 比 K2 優(yōu)呢?在求后面的 FI,K時(shí),K1不一定比 K2 優(yōu)。但是注意到 L1 比 L2 先遞增到 Li,不難證明,假設(shè)求某個(gè) FI, K時(shí),決策 K1 不比K2 優(yōu)了,對(duì)于今后的求解,K1 也決不比 K2 優(yōu)。通過(guò)上面兩步,就能證明決策單調(diào)。接下來(lái)就能運(yùn)用一個(gè)隊(duì)列來(lái)優(yōu)化算法了:(1)開(kāi)一個(gè)隊(duì)列K,隊(duì)列中元素表示他們?cè)诮窈笥锌赡艹蔀樽顑?yōu)決策量,并且 K1K2= Rthen exit;i :=L; j :

8、=R; x :=nodetrunc(random * (R - L + 1) + L;repeatwhile nodei.s x.s do dec(j);if i j;sort(L, j); sort(i, R);end;sort:=nodej; nodej :=temp;procedure var i, j,queue beginsort(1,solve;k, st,ed, s: long;: array1 . maxm of long;n);for i :=1 to ndo beginst :=1; ed :=0;for j :=1fi, j if fi,to m do begin:=fi - 1, j;j - 1 fi, jthen fi, j :=fi, j - 1;if (st = nodei.S) and (j fi, j then fi, j :=s;end;then從隊(duì)首取最優(yōu)決策if (st = nodei.L) then inc(st); 刪除隊(duì)首元素 if (j = nodei.s) then beginwhile (st = (j - queueed) * nodei.P) dodec(ed);inc(ed); queueed :=j; end;thenend;for j end;for iend;solve新決策

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝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ù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論