1 / 4

10724: Road Construction

10724: Road Construction. ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 10 724: Road Construction 解題者: 徐文宏 解題日期: 20 11 年 4 月 20 日 題意: 給一個座標圖 (-1000~1000) ,上有任意數點 N(N<50) ,和連接起來的線段 M(M<1225) 。 求出若增加一個最小的邊,使之任意 2 點最小距離的和有最小值,該邊為何,以題目所給定的點 (1 、 2 、 3……) 作為輸出。.

hubert
Télécharger la présentation

10724: Road Construction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 10724: Road Construction • ★★★☆☆ • 題組:Contest Archive with Online Judge • 題號:10724: Road Construction • 解題者:徐文宏 • 解題日期:2011年4月20日 • 題意:給一個座標圖(-1000~1000),上有任意數點N(N<50),和連接起來的線段M(M<1225)。 求出若增加一個最小的邊,使之任意2點最小距離的和有最小值,該邊為何,以題目所給定的點(1、2、3……)作為輸出。

  2. 題意範例:4 6 0 0 0 2 2 0 22 1 2 1 3 1 4 2 3 2 4 3 4 >No road required 4 4 0 0 0 2 2 0 2 2 1 2 2 3 3 4 4 1 >1 3 • 解法:用Floyd-Warshall algorithm算出任意2點間最點的距離,再用迴圈嘗試尚未加入的邊,在加入後的總距離是否有最小,以及是否為最小的邊

  3. 解法範例: Floyd-Warshall algorithmfor k ← 1 to n do for i ← 1 to n do for j ← 1 to n do if (Di,k + Dk,j < Di,j) then Di,j ← Di,k + Dk,j; 題目給的計算是否距離和最小的公式 Cuv = Sum (PreCostij -CurCostij)

  4. 討論: (1)並非有向量,是單純的線段,但要以2維矩陣來表示,在運算上記得要對稱a[1][2]=a[2][1] (2)題目要求的C,要最大,表示為跟原先的差距,若為正的,表示增加的邊有縮短的效果 (3)時間複雜度為 O(n^3)(FW algorithm)+ O(n^4)= O(n^4)

More Related