Treść książki

Przejdź do opcji czytnikaPrzejdź do nawigacjiPrzejdź do informacjiPrzejdź do stopki
Ants
Contest:PolishCollegiateProgrammingContest2011
Taskauthor:SzymonAcedański
Memory:6mb
https://oi.edu.pl/en/archive/amppz/2011/drz
szymonacedański/ants
22
Computergeeksliketrees.Antsalsoliketrees.Tereforewearegivenatree
withtwoantswalkingonitżtheLeftAntandtheRightAntżasshowninthe
figureabove.Teantswalkalongthepathdepictedbyadottedline.Teystart
theirjourneyatthelowerendofthetrunk,onoppositesides.TeLeftAnt
needs2secondstowalkalongasingleedgeofthetreeifwalkingfromtheroot
(upwards),and1secondifwalkingtowardstheroot(downwards).TeRight
Antistwotimesfaster.Whenthetwoantsmeet,theybothturnaroundand
startwalkingintheoppositedirection.Ifeitheroftheantsstepsfromthetree
totheground,itimmediatelystartstoclimbuptheoppositesideofthetrunk.
Apartfromthat,theantsaresotinythattheywouldnotbevisibleevenunder
amicroscope(theyareintentionallydepictedmuchlargerinthefigure).Your
taskistowriteaprogramthatcomputesthemomentwhentheantsturnaround
forthesecondtime.