「挑戰」有趣的小問題 |
尚未結案
|
goodfriend
一般會員 發表:2 回覆:6 積分:1 註冊:2002-06-26 發送簡訊給我 |
前幾天看到了一個問題
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
將1~24這24個正整數分成三組,每組8個數字,且8個數字合為100
請問有幾種分法
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 覺得滿有趣的,所以我就寫了一下 我寫了50行,程式在我的AMD 1.5G上跑了30秒 我想不會有人比我快了~~~~~~ 所以我來挑戰一下,看有沒有人寫得比我快
|
richtop
資深會員 發表:122 回覆:646 積分:468 註冊:2003-06-10 發送簡訊給我 |
|
goodfriend
一般會員 發表:2 回覆:6 積分:1 註冊:2002-06-26 發送簡訊給我 |
不要直接印出答案就行了 這是我寫的
********************************************** program Project1; uses SysUtils; const max_int:integer=24; max_depth:integer=8; mysum:integer=100; var count:integer=0; count2:integer=0; num_array:array[0..20000] of integer; procedure xxxyyy(depth,cur_int,sum,num:integer); var temp:integer; begin if (cur_int>max_int) then exit; if (depth>max_depth) then exit; if (depth=max_depth) then begin if (sum cur_int = mysum) then begin temp:=num or ( 1 shl (cur_int -1)); num_array[count]:=temp; count:=count 1; exit; end; end; xxxyyy(depth 1,cur_int 1,sum cur_int,num or ( 1 shl (cur_int -1))); xxxyyy(depth ,cur_int 1,sum ,num); end; var i,j,a,temp,bitnum:integer; begin xxxyyy(1,1,0,0); for i:=0 to count do for j:=i 1 to count do begin temp:=num_array[i] or num_array[j]; bitnum:=0; for a:=23 downto 0 do if (temp and (1 shl a))>1 then bitnum:=bitnum 1; if (bitnum=16) then count2:=count2 1; end; writeln(count2); sleep(2000); end. **********************************************發表人 - goodfriend 於 2004/11/04 02:01:10 |
shpeng
初階會員 發表:6 回覆:67 積分:49 註冊:2002-12-21 發送簡訊給我 |
|
goodfriend
一般會員 發表:2 回覆:6 積分:1 註冊:2002-06-26 發送簡訊給我 |
|
goodfriend
一般會員 發表:2 回覆:6 積分:1 註冊:2002-06-26 發送簡訊給我 |
|
daniel__lee
高階會員 發表:18 回覆:124 積分:113 註冊:2002-11-10 發送簡訊給我 |
|
無故障
一般會員 發表:17 回覆:69 積分:17 註冊:2004-03-11 發送簡訊給我 |
|
gglee
一般會員 發表:0 回覆:2 積分:0 註冊:2003-11-27 發送簡訊給我 |
|
goodfriend
一般會員 發表:2 回覆:6 積分:1 註冊:2002-06-26 發送簡訊給我 |
|
Royce520
高階會員 發表:18 回覆:157 積分:100 註冊:2002-09-13 發送簡訊給我 |
|
goodfriend
一般會員 發表:2 回覆:6 積分:1 註冊:2002-06-26 發送簡訊給我 |
引言: goodfriend 你好, 很有趣的題目, 值得一試 ... 你的程式看起來是使用 recursive 解題, 所以應該比 iterative 的方式慢的多, 因此, 應該有跑的更快的寫法^_^~~~並不是所有的recursive都比iterative慢 尤其是一些用recursive很好解但是用iterative很難解的問題 這個問題是一個大陸人提出來的問題,他們老師出了這個題目 剛好我看到了,我覺得蠻有趣的 於是就幫他寫了出來 不過我一直覺得我的做法並不完美 應該還有更快的方法 所以來這挑戰一下~~~~~ |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |