• 沒有找到結果。

d087: Collecting Treasures

N/A
N/A
Protected

Academic year: 2022

Share "d087: Collecting Treasures"

Copied!
48
0
0

加載中.... (立即查看全文)

全文

(1)

d087: Collecting Treasures

Po-Lung Chen

Team Dont Block Me, National Taiwan University

Po-Lung Chen (Dont block me) d087: Collecting Treasures 1 / 31

(2)

Problem Description

Given M open intervals as platforms.

One can move from platform A to platform B if A and B overlap.

Travel from one starting platform toevery other platformsexactly onceand back.

Po-Lung Chen (Dont block me) d087: Collecting Treasures 2 / 31

(3)

Problem Description

Given M open intervals as platforms.

One can move from platform A to platform B if A and B overlap.

Travel from one starting platform toevery other platformsexactly onceand back.

Po-Lung Chen (Dont block me) d087: Collecting Treasures 2 / 31

(4)

Problem Description

Given M open intervals as platforms.

One can move from platform A to platform B if A and B overlap.

Travel from one starting platform toevery other platformsexactly onceand back.

Po-Lung Chen (Dont block me) d087: Collecting Treasures 2 / 31

(5)

Problem Description

Given M open intervals as platforms.

One can move from platform A to platform B if A and B overlap.

Travel from one starting platform toevery other platformsexactly onceand back.

Po-Lung Chen (Dont block me) d087: Collecting Treasures 2 / 31

(6)

Notes

We may construct aninterval graph for the problem.

The problem is equivalent to find aHamilton cycleon this interval graph.

However, finding a Hamilton cycle on the general graph is NP-complete.

But in this “special” graph we can solve it by agreedy algorithm.

Po-Lung Chen (Dont block me) d087: Collecting Treasures 3 / 31

(7)

Notes

We may construct aninterval graph for the problem.

The problem is equivalent to find aHamilton cycleon this interval graph.

However, finding a Hamilton cycle on the general graph is NP-complete.

But in this “special” graph we can solve it by agreedy algorithm.

Po-Lung Chen (Dont block me) d087: Collecting Treasures 3 / 31

(8)

Notes

We may construct aninterval graph for the problem.

The problem is equivalent to find aHamilton cycleon this interval graph.

However, finding a Hamilton cycle on the general graph is NP-complete.

But in this “special” graph we can solve it by agreedy algorithm.

Po-Lung Chen (Dont block me) d087: Collecting Treasures 3 / 31

(9)

Notes

We may construct aninterval graph for the problem.

The problem is equivalent to find aHamilton cycleon this interval graph.

However, finding a Hamilton cycle on the general graph is NP-complete.

But in this “special” graph we can solve it by agreedy algorithm.

Po-Lung Chen (Dont block me) d087: Collecting Treasures 3 / 31

(10)

The Algorithm

Keeping two paths starting from the leftmost interval.

Each time we consider the path with smallerendpoint.

Among all intervals which overlap with this path, we pick the interval with smallestendpoint.

If there is no interval overlap with the path, the answer is “no”.

Finally we will get two paths, check if the last interval at both paths overlap.

Po-Lung Chen (Dont block me) d087: Collecting Treasures 4 / 31

(11)

The Algorithm

Keeping two paths starting from the leftmost interval.

Each time we consider the path with smallerendpoint.

Among all intervals which overlap with this path, we pick the interval with smallestendpoint.

If there is no interval overlap with the path, the answer is “no”.

Finally we will get two paths, check if the last interval at both paths overlap.

Po-Lung Chen (Dont block me) d087: Collecting Treasures 4 / 31

(12)

The Algorithm

Keeping two paths starting from the leftmost interval.

Each time we consider the path with smallerendpoint.

Among all intervals which overlap with this path, we pick the interval with smallestendpoint.

If there is no interval overlap with the path, the answer is “no”.

Finally we will get two paths, check if the last interval at both paths overlap.

Po-Lung Chen (Dont block me) d087: Collecting Treasures 4 / 31

(13)

The Algorithm

Keeping two paths starting from the leftmost interval.

Each time we consider the path with smallerendpoint.

Among all intervals which overlap with this path, we pick the interval with smallestendpoint.

If there is no interval overlap with the path, the answer is “no”.

Finally we will get two paths, check if the last interval at both paths overlap.

Po-Lung Chen (Dont block me) d087: Collecting Treasures 4 / 31

(14)

Illustration

1- 1-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 5 / 31

(15)

Illustration

1- 1-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 6 / 31

(16)

Illustration

1-2- 1-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 7 / 31

(17)

Illustration

1-2- 1-9-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 8 / 31

(18)

Illustration

1-2- 1-9-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 9 / 31

(19)

Illustration

1-2- 1-9-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 10 / 31

(20)

Illustration

1-2-3- 1-9-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 11 / 31

(21)

Illustration

1-2-3- 1-9-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 12 / 31

(22)

Illustration

1-2-3- 1-9-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 13 / 31

(23)

Illustration

1-2-3- 1-9-8-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 14 / 31

(24)

Illustration

1-2-3- 1-9-8-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 15 / 31

(25)

Illustration

1-2-3- 1-9-8-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 16 / 31

(26)

Illustration

1-2-3- 1-9-8-4-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 17 / 31

(27)

Illustration

1-2-3- 1-9-8-4-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 18 / 31

(28)

Illustration

1-2-3- 1-9-8-4-7-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 19 / 31

(29)

Illustration

1-2-3- 1-9-8-4-7-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 20 / 31

(30)

Illustration

1-2-3-5- 1-9-8-4-7-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 21 / 31

(31)

Illustration

1-2-3-5- 1-9-8-4-7-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 22 / 31

(32)

Illustration

1-2-3-5- 1-9-8-4-7-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 23 / 31

(33)

Illustration

1-2-3-5- 1-9-8-4-7-6-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 24 / 31

(34)

Illustration

1-2-3-5- 1-9-8-4-7-6-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 25 / 31

(35)

Illustration

1-2-3-5 1-9-8-4-7-6-

Po-Lung Chen (Dont block me) d087: Collecting Treasures 26 / 31

(36)

Illustration (Finished!)

1-2-3-5 1-9-8-4-7-6

Now we have to check whether 5 and 6 overlap or not.

Po-Lung Chen (Dont block me) d087: Collecting Treasures 27 / 31

(37)

Illustration (Finished!)

1-2-3-5 1-9-8-4-7-6

Now we have to check whether 5 and 6 overlap or not.

Po-Lung Chen (Dont block me) d087: Collecting Treasures 27 / 31

(38)

Naïve Implementation

For each time, we scan onall intervals and find the interval we want.

This cost O(n) per iteration.

Total time complexity is O(n2).

Can we solve this problem faster?

Po-Lung Chen (Dont block me) d087: Collecting Treasures 28 / 31

(39)

Naïve Implementation

For each time, we scan onall intervals and find the interval we want.

This cost O(n) per iteration.

Total time complexity is O(n2).

Can we solve this problem faster?

Po-Lung Chen (Dont block me) d087: Collecting Treasures 28 / 31

(40)

Naïve Implementation

For each time, we scan onall intervals and find the interval we want.

This cost O(n) per iteration.

Total time complexity is O(n2).

Can we solve this problem faster?

Po-Lung Chen (Dont block me) d087: Collecting Treasures 28 / 31

(41)

Naïve Implementation

For each time, we scan onall intervals and find the interval we want.

This cost O(n) per iteration.

Total time complexity is O(n2).

Can we solve this problem faster?

Po-Lung Chen (Dont block me) d087: Collecting Treasures 28 / 31

(42)

Carefully Implementation

From the view of thecandidateintervals,

each interval will goes into the set once, and be picked out once, too.

There are a total of O(n) add/remove operations to the set of candidate intervals.

Po-Lung Chen (Dont block me) d087: Collecting Treasures 29 / 31

(43)

Carefully Implementation

From the view of thecandidateintervals,

each interval will goes into the set once, and be picked out once, too.

There are a total of O(n) add/remove operations to the set of candidate intervals.

Po-Lung Chen (Dont block me) d087: Collecting Treasures 29 / 31

(44)

Carefully Implementation

From the view of thecandidateintervals,

each interval will goes into the set once, and be picked out once, too.

There are a total of O(n) add/remove operations to the set of candidate intervals.

Po-Lung Chen (Dont block me) d087: Collecting Treasures 29 / 31

(45)

Carefully Implementation (Contd.)

The interval we want in the candidate set is the one withsmallest endpoint.

If we use a heaporsegment tree, we can update the candidate set in O(log n) time per operation.

The overall time complexity is O(n log n).

Po-Lung Chen (Dont block me) d087: Collecting Treasures 30 / 31

(46)

Carefully Implementation (Contd.)

The interval we want in the candidate set is the one withsmallest endpoint.

If we use a heaporsegment tree, we can update the candidate set in O(log n) time per operation.

The overall time complexity is O(n log n).

Po-Lung Chen (Dont block me) d087: Collecting Treasures 30 / 31

(47)

Carefully Implementation (Contd.)

The interval we want in the candidate set is the one withsmallest endpoint.

If we use a heaporsegment tree, we can update the candidate set in O(log n) time per operation.

The overall time complexity is O(n log n).

Po-Lung Chen (Dont block me) d087: Collecting Treasures 30 / 31

(48)

Thank you for your listening!

Po-Lung Chen (Dont block me) d087: Collecting Treasures 31 / 31

參考文獻

相關文件

In particular, we present a linear-time algorithm for the k-tuple total domination problem for graphs in which each block is a clique, a cycle or a complete bipartite graph,

《禪定目炬》藏文全名是 gNub chen Sangs rgyas ye shes rin po ches mdzad pa’i sGom gyi gnad gsal bar phye ba bsam gtan mig

Study the following statements. Put a “T” in the box if the statement is true and a “F” if the statement is false. Only alcohol is used to fill the bulb of a thermometer. An

A conical flask containing oil and water A sectional diagram of the set-up Examples of drawing experimental apparatus.. Apparatus

Chen, The semismooth-related properties of a merit function and a descent method for the nonlinear complementarity problem, Journal of Global Optimization, vol.. Soares, A new

Bingham & Sitter (2001) used the usual minimum-aberration criterion for unblocked designs to compare split-plot designs, but since it often leads to more than one

• Actually what Hawking said was, Event Horizon may not exist, the only thing real is the Apparent Horizon. • Apparent horizon can trap matter and lights, but as the BH

Chen, Conditions for error bounds and bounded level sets of some merit func- tions for the second-order cone complementarity problem, Journal of Optimization Theory and