4
1 10049: Selfdescribing Sequence ★★★ 題題Problem Set Archive with Online Judge 題題Problem C: Selfdescribing Sequence 題題題林林林 題題題題2006 林 3 林 21 林 題題Solomon Golomb 林林林林林林林selfdescribing sequenc e )< f(1), f(2), f(3), ...... 林林 林林林 林林林林林林林 林林林林林林林林 >一一。 林林林林 k 林林林林林林林林林 f(k) 林 林 n 林 f(n) 1<=N<=2,000,000,000

10049: Selfdescribing Sequence

Embed Size (px)

DESCRIPTION

10049: Selfdescribing Sequence. ★★★ 題組: Problem Set Archive with Online Judge 題號: Problem C: Selfdescribing Sequence 解題者: 林峰世 解題日期: 2006年3月 21 日 題意: Solomon Golomb 的自我描述序列( selfdescribing sequence )< f(1), f(2), f(3), ...... >是一個唯一的不下降序列。在此序列的正整數的特質為 k 在序列中會出現連續 f(k) 次。 - PowerPoint PPT Presentation

Citation preview

Page 1: 10049:  Selfdescribing Sequence

1

10049: Selfdescribing Sequence ★★★ 題組: Problem Set Archive with Online Judge 題號: Problem C: Selfdescribing Sequence 解題者:林峰世 解題日期: 2006 年 3 月 21 日 題意: Solomon Golomb 的自我描述序列( selfdescribing

sequence )< f(1), f(2), f(3), ...... >是一個唯一的不下降序列。在此序列的正整數的特質為 k在序列中會出現連續 f(k) 次。

給 n 求 f(n) 1<=N<=2,000,000,000

Page 2: 10049:  Selfdescribing Sequence

2

題意範例:

你可以看到 n=1, f(n)=1 ,代表 1 會在序列中出現 1 次。 n=2, f(2)=2 ,代表 2 會在序列中出現2 次。 n=3, f(3)=2 ,代表 3 會在序列中出現 2次。 n=4, f(4)=3 ,代表 4 會在序列中出現 3 次。依此類推,若 f(k)=x ,則 k會在序列中出現 x 次。

Page 3: 10049:  Selfdescribing Sequence

3

解法:用一個二維矩陣 a[4810][2] 存放紀錄 , 因為儲存整個表太大 , 所以儲存可 一個簡表 , 由這個表我們可以簡單推導到整個 f(n)

a[i][0] 到 a[i+1][0] 之間同樣的 f(n) 會重複 i 次 .a[i][1] 則等於 f(a[i][0])

sd[1][0]=1 sd[2][0]=2

sd[1][1]=1 sd[2][1]=2建立簡表的規則 : (ib == i-1)

sd[i][0] = sd[ib][0] + f(ib)*ib; f(n) = (n - sd[i][0])/i+sd[i][1];

sd[i][1] = (sd[i][0]-sd[ib][0])/ib + sd[ib][1];從前面開始建立 ,後面的就可以從前面的推導到

1 2 6 12 24 39 63 91

1 2 4 6 9 12 16 20

Page 4: 10049:  Selfdescribing Sequence

4

解法範例:無

討論:用這樣的方式用 [5000][2] 的 array 就可以推導到n=1~2000000000 的 f(n)