220 likes | 482 Views
Shark. 99703041 謝佳佑 99703043 蘇 柏瑋 97306011 黃泓彰. 830-Shark. Problem introduction Discussion Solution. Problem introduction. Problem There are several attacks by sharks. The local guardians are worried, so they decide to implement an automated shark detection.
E N D
Shark 99703041謝佳佑 99703043蘇柏瑋 97306011黃泓彰
830-Shark • Problem introduction • Discussion • Solution
Problem introduction • Problem There are several attacks by sharks. The local guardians are worried, so they decide to implement an automated shark detection. Detection is rather sophisticated, since not all sea animals are sharks.
Problem introduction • Sardine 沙丁魚
Problem introduction • Mackerel 青魚
Problem introduction • Salmon 鮭魚
Problem introduction • Turtle 烏龜
Problem introduction • Grouper 石斑魚
Problem introduction • Dolphin 海豚
Problem introduction • Shark 鯊魚
Problem introduction • Whale 鯨魚
Problem introduction • Input b...c.fgh... baabca.jkyyy ...bcak..yyy ....ca...yyy zzzzzz...uuu zzzzzz.s.uuu zzzzzzsssuuu .tttt.sssuuu ttttt.sssuuu .tttt.sss.u. .........hh. bbbb..fffhh. bbbb..fffhh. bbbbgggg.hh. bbbbgggg.ppp bbbbgggg.ppp • Output Sardines: 6 Mackerels: 3 Salmons: 2 Groupers: 3 Turtles: 1 Dolphins: 2 Whales: 1 Sharks: 3
Discussion • Possible Solutions • Search for each kind of animal. • Search for an animal, then classify.
Solution • Pseudo-code Input = char [m][n] IsVisited = bool [m][n] with initial value FALSE FOREACH point(i, j) in Input IF point(i, j) != ‘.’ AND NOT IsVisited[i][j] Get length Get width Visit all points, set to TRUE Classification ENDIF
Solution • What’s problem? A Fin-on-the-top Shark!
Solution • Time complexity • A total of k animals in an m * n matrix, each with length lk and width wk • c as a constant while classification • (mn – k) + k (Σ lk + Σ wk + c + Σ(lkwk)) = Θ(mnk)
Solution • Time complexity • Worst case: All sardines • k = mn • (mn – k) + k (Σ lk + Σ wk + c + Σ(lkwk)) = 0 + (mn) (mn + mn + c + mn) = 3(mn)2 + cmn • Θ((mn)2)
Solution • Time complexity • Best case: A extremely big whale (or turtle) • k = 1 • (mn – k) + k (Σ lk + Σ wk + c + Σ(lkwk)) = (mn - 1) + (m + n + c + mn) = 2mn + m + n + c - 1 • Θ(mn)
Solution • Time complexity • 1 ≤ k ≤ mn • mn ≤ mnk ≤ (mn)2 • Θ(mnk)
Solution • Result DEMO http://140.119.19.129:10080/