Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please solve in Java or C + + , thank you. : ) Bessie has mastered the art of turning into a cannonball and bouncing
Please solve in Java or C thank you. :
Bessie has mastered the art of turning into a cannonball and bouncing along a number line of length with
locations numbered dots, from left to right. She starts at some integer location bouncing to the right with a
starting power of If Bessie has power her next bounce will be at a distance forward from her current location.
Every integer location from to is either a target or a jump pad. Each target and jump pad has an integer value in the range
to inclusive. A jump pad with a value of increases Bessie's power by and reverses her direction. A target with a value of
will be broken if landed on with a power of at least Landing on a target does not change Bessie's power or direction. A target
that is broken will remain broken and Bessie can still bounce on it also without changing power or direction.
If Bessie bounces for an infinite amount of time or until she leaves the number line, how many targets will she break?
If Bessie starts on a target that she can break, she will immediately do so Similarly, if Bessie starts on a jump pad, the pad's
effects will be applied before her first jump.
INPUT FORMAT input arrives from the terminal stdin:
The first line of the input contains and where is the length of the number line and is Bessie's starting location.
The next lines describe each of the locations. The th of these lines contains integers and where if location is a
jump pad and if location is a target, and where is the value of location
OUTPUT FORMAT print output to the terminal stdout:
Output one number representing the number of targets that will be broken.
SAMPLE INPUT:
SAMPLE OUTPUT:
Bessie starts at coordinate which is a target of value so she immediately breaks it She then bounces to coordinate which
is a target of value so she can't break it She continues to coordinate which switches her direction and increases her power
by to She bounces back to coordinate which is an already broken target, so she continues. At this point, she bounces to
coordinate so she stops. She breaks exactly one target at located at
SAMPLE INPUT:
SAMPLE OUTPUT:
The path Bessie takes is where the next bounce would take her out of the number line She breaks
targets in that order.
SCORING:
Inputs :
Inputs :
Inputs : No additional constraints.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started