Answered step by step
Verified Expert Solution
Link Copied!

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 N(1N105) with
locations numbered 1,2,dots,N from left to right. She starts at some integer location S(1SN) bouncing to the right with a
starting power of 1. If Bessie has power k, her next bounce will be at a distance k forward from her current location.
Every integer location from 1 to N is either a target or a jump pad. Each target and jump pad has an integer value in the range 0
to N inclusive. A jump pad with a value of v increases Bessie's power by v and reverses her direction. A target with a value of v
will be broken if landed on with a power of at least v. 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 N and S, where N is the length of the number line and S is Bessie's starting location.
The next N lines describe each of the locations. The i th of these lines contains integers qi and vi, where qi=0 if location i is a
jump pad and qi=1 if location i is a target, and where vi is the value of location i.
OUTPUT FORMAT (print output to the terminal / stdout):
Output one number representing the number of targets that will be broken.
SAMPLE INPUT:
SAMPLE OUTPUT:
1
Bessie starts at coordinate 2, which is a target of value 1, so she immediately breaks it. She then bounces to coordinate 3, which
is a target of value 2, so she can't break it. She continues to coordinate 4, which switches her direction and increases her power
by 1 to 2. She bounces back to coordinate 2, which is an already broken target, so she continues. At this point, she bounces to
coordinate 0, so she stops. She breaks exactly one target at located at 2.
SAMPLE INPUT:
64
03
11
12
11
01
11
SAMPLE OUTPUT:
3
The path Bessie takes is 45316, where the next bounce would take her out of the number line (11). She breaks
targets 4,3,6 in that order.
SCORING:
Inputs 3-5: N100
Inputs 6-10: N1000
Inputs 11-20: No additional constraints.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Objects And Databases International Symposium Sophia Antipolis France June 13 2000 Revised Papers Lncs 1944

Authors: Klaus R. Dittrich ,Giovanna Guerrini ,Isabella Merlo ,Marta Oliva ,M. Elena Rodriguez

2001st Edition

3540416641, 978-3540416647

More Books

Students also viewed these Databases questions

Question

What are the objectives of job evaluation ?

Answered: 1 week ago

Question

Write a note on job design.

Answered: 1 week ago

Question

Compute the derivative of f(x)cos(-4/5x)

Answered: 1 week ago

Question

Discuss the process involved in selection.

Answered: 1 week ago