Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 11082: Matrix Decompressing ★★★★☆ 題組: Contest Volumes with Online Judge 題號: 11082: Matrix Decompressing 解題者:蔡權昱、劉洙愷 解題日期: 2008 年 4 月 18 日 題意:假設有一矩陣 R*C,

Similar presentations


Presentation on theme: "1 11082: Matrix Decompressing ★★★★☆ 題組: Contest Volumes with Online Judge 題號: 11082: Matrix Decompressing 解題者:蔡權昱、劉洙愷 解題日期: 2008 年 4 月 18 日 題意:假設有一矩陣 R*C,"— Presentation transcript:

1 1 11082: Matrix Decompressing ★★★★☆ 題組: Contest Volumes with Online Judge 題號: 11082: Matrix Decompressing 解題者:蔡權昱、劉洙愷 解題日期: 2008 年 4 月 18 日 題意:假設有一矩陣 R*C, (1 ≤ R,C ≤ 20), 若告訴 你每列與每行連續相加的總和,請分解 row 與 column 的總和,還原成原來的矩陣元素。全部 T 組矩陣 (1 ≦ T ≦ 100) ,每個矩陣大小為 row R(1 ≦ R ≦ 20) , column C(1 ≦ C ≦ 20) 。輸出時每個矩 陣元素要 1 ≦ X ≦ 20 。

2 2 題意範例: Sample Input Sample Output 2 // 兩組矩陣 Matrix 1 3 4// 大小 3*41 6 1 2 (sum = 10) 10 31 58 //R 總和 1 2 2 16 (sum = 21) 10 20 37 58 //C 總和 8 2 14 3 (sum = 27) (10 10 17 21) 3 4 Matrix 2 10 31 58 1 1 1 7 10 20 37 58 1 1 7 12 8 8 9 2 解法 1( 劉洙愷 ) :利用每列或每行的合與全部總和的平均 去配點填數字。

3 3 解法範例: 前置動作:因為每個元素需要 1 ≦ X ≦ 20 ,所 以先每個元素給 1 。 1111 (6) 1111 (17) 1111 (23) (7) (7) (14) (18) example for 分配點數: (1) 23 * 7 / (7 + 7 + 14 + 18 = 46 ) = 3.5 ≒ 4 (2) 23 * 7 / 46 = 3.5 ≒ 4 (3) 23 * 14 / 46 = 7 (4) 23 – 4 – 4 – 7 = 8

4 4 解法範例 (con.) : 1111 (6) 1111 (17) 5589 (0) (3) (3) (7) (10) 然後依此列推往下做。

5 5 討論: (1) 用平均配點方式是為了讓元素不要超過限制。 (2) 但是如果矩陣很大,取值又要整數,這樣會有小數 的誤差,到最後一列或最後一排的元素容易超過限制。

6 6 解法 2 ( 蔡權昱 ) :整理後代 Greedy 解即可. 解法範例 1 : 我們可以先把題目轉成以下型態 : 000010 000021 000027 10101721 又因為每個元素≧ 1: 11116 111117 111123 771418 6

7 7 解法範例 1 : 11116 111117 111123 771418 7

8 8 解法範例 1 : 11116 111117 111123 771418 111195 77140 8

9 9 解法範例 1 : 11116 111117 111123 771418 111195 77140 116190 7790 9

10 10 解法範例 1 : 11116 111117 116190 7790 10

11 11 解法範例 1 : 11116 111117 116190 7790 111018 7700 11

12 12 解法範例 1 : 11116 111117 116190 7790 111018 7700 181011 7000 12

13 13 解法範例 1 : 11116 111117 116190 7790 111018 7700 181011 7000 281010 6000 13

14 14 解法範例 1 : 11116 281010 116190 6000 14

15 15 解法範例 1 : 11116 281010 116190 6000 71110 0000 15

16 16 解法範例 1 : 711110 28101 21 11619 27 10101721 FINISH! 16

17 17 解法範例 2 : 00030 00030 102723 11127 11127 82521 17

18 18 解法範例 2 : 11127 11127 82521 18

19 19 解法範例 2 : 11127 11127 82521 12018 8621 12090 8613 19

20 20 解法範例 2 : 12090 11127 8613 20

21 21 解法範例 2 : 12090 11127 8613 111414 860 91146 060 97140 000 21

22 22 解法範例 2 : 120930 971430 102723 FINISH! 22

23 23 討論: 1 ≤ entry ≤ 20, 平行位移. sort(n=20) = 86.4 ≒ Constant 建置一個矩陣 : O( sort(20) + N * sort(20) ) = O( (N+1) * sort(20) ) ≒ O( 87N ) 100 * 20 * 87 = 17,4000 cost 0.1s 23


Download ppt "1 11082: Matrix Decompressing ★★★★☆ 題組: Contest Volumes with Online Judge 題號: 11082: Matrix Decompressing 解題者:蔡權昱、劉洙愷 解題日期: 2008 年 4 月 18 日 題意:假設有一矩陣 R*C,"

Similar presentations


Ads by Google