Presentation is loading. Please wait.

Presentation is loading. Please wait.

Senior Q2 Shy Tortoise. Sample >>> ><> <><> <><>> >> 13431.

Similar presentations


Presentation on theme: "Senior Q2 Shy Tortoise. Sample >>> ><> <><> <><>> >> 13431."— Presentation transcript:

1 Senior Q2 Shy Tortoise

2 Sample >>> ><> <><> <><>> >> 13431

3 Statistic Max : 60 Min : 0 Mean : 30 Surprisingly no one get full mark, or even 75%.

4 Simulation 30% while not in order find first ‘<‘, say s[i] ++count[i – 1] ++count[i] swap(s[i – 1], s[i]) A lot of work is done repeatedly (find first ‘<‘).

5 Simulation 50% (Mode) while not in order t = s for each ‘ ’ set t[i – 1] = ‘ ’ ++count[i – 1] ++count[i] s = t

6 Finding direction only - 50% Key observation: number of ‘>’/’ ’. count total number of ‘ ’

7 75% Combine the two 50% solution. Simulation is too slow but is able to count. Counting is fast but unable to count. if n <= 5000 simulation else counting

8 Full solution Consider tortoise ending with ‘<‘. Observation: the tortoise need to turn around only if its left have some ‘>’. More, each ‘>’ contributes 2 turns.

9 Full solution (cont.) e.g. >>><< Consider the second tortoise. It needs 1 turn to make it correct. A ‘>’ in its left contributes 2 more turns. Thus count[2] = 3.

10 Full solution (cont.) set left[1] = 0 for i = 2 to n if s[i – 1] = ‘>’ left[i] = left[i – 1] + 1 else left[i] = left[i – 1] for i = 1 to n count[i] = 2*left[i] if s[i] = ‘>’ ++count[i]


Download ppt "Senior Q2 Shy Tortoise. Sample >>> ><> <><> <><>> >> 13431."

Similar presentations


Ads by Google