Saiko Psycho-Pie

ADA (Algorithm Design and Analysis) HW3-5

Once upon a time...

There was a young warrior

Piepie

At the other side of the kingdom

There was an ambitious sorcerer

QMao

One day...

QMao had this brilliant idea

Psycho-Pie!

不吃還好,一吃不得了!

The old king

Handsome

A single order...

Hunt Down QMao !

Problem Description

Fallen cities

Normal cities

Ada Kingom  -> Qmao's Castle

(Digraph)

P

Q

K = 2

P

Q

Shortest Path!

Dijkstra(V,E) viewed as O(|E| + |V|log|E|)

可以只寫(c)唷!

Mage Academy

Archimage Masschian

(d) - TheraPIE

隨身攜帶一個派!

(e) - Hyperdimensional Shift

P

Q

Relics

Choose one relic among E_2(numbers of relics) !

!!!Revision!!!

Thanks to 楊皓丞。

Time complexity:
O( k*dijkstra(V,E) + E2  ) ->
O( k*(dijkstra(V,E) + E2)  )

(f) - Imperial Army

P

Q

Purification k_2

P

Q

Purification k_2

(g) - Nirvana

P

Q

Nirvana

P

Q

Nirvana

P

Q

Nirvana

完全無視所有Fallen Cities, 度過k_2個城鎮

no poison P

Nirvana

5回內要吃派 P

no poison P

5回內要吃派 P

Nirvana

Nirvana

完全保持狀態!

Grading:
max ( (d) , (e) ) +
max ( (f), (g) ) )

兩組二選一寫就好!

Simple Solution

Problem (a)

no-pie-no-pie-no-piepie (k=2,起點有派)

Observation

Sample Solution

拔掉這種邊,丟dijkstra

V,E層級沒變,O(dijk(V,E))

Problem (b)

no-pie-no-pie-no-piepie (k=2,起點沒派)

Sample Solution

策略:
不走派,
走到一定時間後開始一直吃派。

Sample Solution

完全不走派(把所有派點對外的邊拿掉) 的圖稱為G_b

一直吃派的圖(Problem a)
稱作G_a

Sample Solution

對G_b從起點做dijkstra
對G_a從終點,把邊反向做dijkstra

Sample Solution

P

Q

d_G_b(v)

d_G_a(v)

Sample Solution

\min_{v \in V}(d_a[v] + d_b[v])
minvV(da[v]+db[v])\min_{v \in V}(d_a[v] + d_b[v])

O( 2 * dijk(V,E) + V ) = O(dijk(V,E))

Problem (c)

regular problem

Sample Solution

拆成好幾個世界

每個世界都代表現在派派的狀態。

Sample Solution

G no poison

G left k

G left k-1

G left 1

...

Break Through the world

G no poison

G left k

G left k-1

G left k

G left k

G left k-2

G left k-1

G left k

G no poison

Break Through the world

G no poison

G left k

G no poison

Break Through the world

G left i

G left k

G left i-1

if ( i > 1 )

Some trivials ...

P

P

P

P

Q

Q

Q

Q

P'

Q'

如果P沒派

如果P有派

O(  dijk(kV,kE) )
= O( kE + kvlogkv )
= O( kE + kv(logk + logv))
= O(kE + kvlogv)
= O(k (E + vlogv))
= O(k * dijk(V,E))

Time complexity

需要把 k>v 特判!

Problem (d)

TheraPIE

假設G_c 為
problem c的世界

Sample Solution

Sample Solution

Graph C with TheraPIE

Graph C without TheraPIE

由 k = 1 接到 k = k

Sample Solution

同problem C:
O( 2 * k * dijk(V,E))
= O( k * dijk(V,E) )

Problem (e)

Hyperdimensional Shift

start -> 傳送點前 ->
傳送點後 -> 終點

Sample Solution

假設G_c 為
problem c的世界

Sample Solution

Sample Solution

對G_c從起點做dijkstra (d_a)
(start 到傳送點前)

對G_c從終點,把邊反向做dijkstra (d_b)
(傳送點後到終點)

Sample Solution

傳送點前後
世界同problem(c)要接好。

Sample Solution

\min_{(u,v) \in E_2}(d_a[u] + d_b[v])
min(u,v)E2(da[u]+db[v])\min_{(u,v) \in E_2}(d_a[u] + d_b[v])

O( 2 * dijk(V,E) + kE_2 ) = O(dijk(V,E) + kE_2)

Problem (f)

Imperial Army

當你中毒,
你就不會去淨化城鎮。
(只有還沒中毒才會淨化)

Sample Solution

Sample Solution

G no poison

G left k step

G left 1 step

...

G left k_2-1 times

G left k_2-2 times

G left 1 times

...

Break Through the world

G no poison

G left k step

G no poison

G left k_2-1
times

Break Through the world

G left k step

G left i times

G left i-1
times

G left i times

Break Through the world

G left i step

G left k step

G left i-1 step

if ( i > 1 )

Some trivials ...

同problem C

Time complexity

O((k+k2) dijk(V,E)),寫法同C

Problem (g)

Nirvana

Sample Solution

假設G2是開nirvana後的世界

G left k2 step

G left k2-1 step

G left 1 step

...

Break Through the world

G left i step

G left i-1 step

if ( i > 1 )

Break Through the world

G no poison

G left k

G left k-1

G left 1

...

G no poison

G left k

G left k-1

G left 1

...

without Nirvana

with Nirvana

Break Through the world

G no poison

G left k

G left k-1

G left 1

...

G no poison

G left k

G left k-1

G left 1

...

without Nirvana

with Nirvana

G2

G2

G2

G2

只到最後step才開nirvana會錯!

Time complexity

O((k1*k2) dijk(V,E)),寫法同C

Saiko Psycho-Pie

By Arvin Liu

Saiko Psycho-Pie

ADA 2018 HW3's Hand-Written Homework1 Problem & Solution

  • 1,200