Presentation is loading. Please wait.

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

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

Senior Q2 Shy Tortoise

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

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

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 ‘<‘).

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

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

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

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

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.

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