Canadian Computing Competition: 2010 Stage 1, Junior #2
Nikky and Byron are playing a silly game in gym class.
Nikky is told by his teacher to walk forward steps (
)
and then walk backward
steps (
), after which he repeats
forward,
backward, etc. Likewise, Byron is told to walk forward
steps (
) and then walk backward
steps (
),
after which he repeats
forward,
backward, etc. You may
assume that
and
.
Byron and Nikky have the same length of step, and they are required to take their steps simultaneously (that is, Nikky and Byron will both step forward on their first steps at the same time, and this will continue for each step).
Nikky and Byron start walking from one end of a soccer field. After
steps (
), the gym teacher will blow the whistle. Your
task is to figure out who has moved the farthest away from the starting
position when the whistle is blown.
Input Specification
The input will be the 5 integers ,
,
,
, and
, each on a
separate line.
Output Specification
The output of your program will be one of three possibilities: Nikky
if
Nikky is farther ahead after steps are taken;
Byron
if Byron is
farther ahead after steps are taken;
Tied
if Byron and Nikky are at
the same distance from their starting position after steps are
taken.
Sample Input
4
2
5
3
12
Output for Sample Input
Byron
Explanation of Output for Sample Input
Notice that after steps, Nikky has moved
steps, for
a total of
steps from the starting position, whereas Byron has moved
steps, for a total of
steps from the starting position.
Thus, Byron is ahead.
Comments
This comment is hidden due to too much negative feedback. Show it anyway.
I made the same mistake and I also want to die :(
This comment is hidden due to too much negative feedback. Show it anyway.
Why is my code exceeding the time limit? I know it's probably related to my two while loops, but I don't see why it would do that.
You could try making a function to find the numbers too. It will make your life much easier
You don't have to iterate so many times, and your calculation method will result in WA even if the time limit will allow your answer. Think about this problem a lot more carefully and read the explanations for the sample outputs.
In the case where Byron or Nikky do not have enough time for the amount of steps, just add or subtract the remaining time depending if he or she is going forward or backward.
Why doesn't my test case #4 work?
Try this testcase (also for others failing testcase #4):
Both Nikky and Byron traveled 5 steps, so the correct output should be
Tied
, notByron
.I Used your input and got tied as my output, however I still got WA when I submit my solution. But still thanks for the tip!
if i input 10 0 20 0 5
i do output tied but i still fail testcase 4
Oh, I think I know what I was doing wrong- thanks!
Spent half an hour spelling Byron as Bryon and Nikky as Nicky.
This comment is hidden due to too much negative feedback. Show it anyway.
That means it outputs 'Tied'.
This comment is hidden due to too much negative feedback. Show it anyway.
How do you know what the test case should be? Think first whether it would be arrogant to suggest all the people who got AC are wrong.
I had read the question statement wrong. I apologize for my previous comment.