Why Did the Cow Cross the Road?

Source: USACO 717

  1. Read the problem and summarise the task requirements.
  2. How would you solve the problem if Bessie ate the grass in every field she visited, rather than every third?
  3. Design an algorithm to solve this simplified problem.
  4. Analyse the time complexity of your algorithm and estimate its running time.

  5. Implement this algorithm in code.

Now we can return to the original problem, where Bessie only eats from every third field.

  1. Adapt your earlier algorithm to solve the full problem.
  2. Analyse the time complexity of your new algorithm and estimate its running time.

  3. Implement this algorithm in code.
  4. Submit your program for judging!